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! Quote 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 Quote 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 Quote 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? Quote 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 Quote 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
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.