I am currently building a site, and one of its function is to display images inside a folder. Apparently the image seems to be displaying in random, and I would like to display them according to the date last added into the folder. This is my current code:
<?php
$pdir = "uploads/photography";
if ($opendir = opendir($pdir)) {
while (($file = readdir($opendir)) !== FALSE) {
if ($file!="." && $file!="..") {
echo "<img height='600px' width='600px' src='$pdir/$file'><br /><br /><br />";
}
}
}
?>
I understand in order to sort the images, I need to add the time added in an array, and then sort that array, however I am not even able to figure the time last added. With filemtime() and fileatime(), I kept on displaying the creation and the last added time of the FOLDER, instead of the IMAGES inside the folder.
I have been searching for the solution for almost 2 days now, either on here or on php.net, and I still don't seem to find the correct solution to my problem. Any kind person can help saving my poor soul would be very much appreciated.
Ray