I've got a basic PHP script (shown below) that simply displays all the images (jpegs) in the directory, in no particular order. I have this code in an 'index.php' file My issue is now I'd like to sort the images in chronological order. I tried messing with the sort() code, but couldn't get it to work. <?php $handle = opendir ('./'); while (false !== ($file = readdir($handle))) { if($file != "." && $file != ".." && $file != basename(__FILE__)) { echo '<img src="'.$file.'"/>'; } } ?> Code (markup): Any help is GREATLY appreciated. Thanks!
try http://php.net/glob use it foreach (glob("*.png") AS $image) { // do something with image } Code (markup): Â
glob does not give you chronological idea. Use filemtime() as follows: $last_modified = filemtime("thisfile.php"); This function returns time in Unix timestamp. Put into array and sort ascending order, then convert to date upon displaying it.