AndrewFerrara Posted January 28, 2011 Share Posted January 28, 2011 I am trying to display images on a html page alphabetically in descending order by their filename. <?php $dir = "./plate_cache"; $handle = opendir($dir); while (($file = readdir($handle))!==false) { if (strpos($file, '.png',1)) { echo "<img id=\"plates\" src=\"/tags/plate_cache/$file\"></a><br />;"; } } closedir($handle); } ?> Any help is greatly appreciated! Link to comment https://forums.phpfreaks.com/topic/225904-displaying-images-from-a-directory-alphabeticaly-in-descending-order-by-filename/ Share on other sites More sharing options...
rondog Posted January 28, 2011 Share Posted January 28, 2011 you can add the filenames to an array then use sort: http://php.net/manual/en/function.sort.php Link to comment https://forums.phpfreaks.com/topic/225904-displaying-images-from-a-directory-alphabeticaly-in-descending-order-by-filename/#findComment-1166307 Share on other sites More sharing options...
.josh Posted January 28, 2011 Share Posted January 28, 2011 use glob and rsort Link to comment https://forums.phpfreaks.com/topic/225904-displaying-images-from-a-directory-alphabeticaly-in-descending-order-by-filename/#findComment-1166308 Share on other sites More sharing options...
AndrewFerrara Posted January 28, 2011 Author Share Posted January 28, 2011 could u fix the code I have little experience with php... what's an array? Link to comment https://forums.phpfreaks.com/topic/225904-displaying-images-from-a-directory-alphabeticaly-in-descending-order-by-filename/#findComment-1166311 Share on other sites More sharing options...
BlueSkyIS Posted January 28, 2011 Share Posted January 28, 2011 what's an array? http://php.net/manual/en/language.types.array.php Link to comment https://forums.phpfreaks.com/topic/225904-displaying-images-from-a-directory-alphabeticaly-in-descending-order-by-filename/#findComment-1166323 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.