0

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

Ray Wai
  • 35
  • 6
  • 1
    See http://stackoverflow.com/questions/2667065/sort-files-by-date-in-php – Ben Claar Jul 29 '15 at 00:24
  • First of all, thank you for the reply. – Ray Wai Jul 29 '15 at 08:54
  • I have already read through the page earlier before opening this discussion, but I am not able to come to a conclusion, and after reading it again, I still cannot solve my problem. The problem is that I encounter errors at the filemtime function, it states "Warning: filemtime(): stat failed for mypic.jpg". My guess is that it could not register the time the images added/created inside the files. Any input will be so much appreciated. Thanks. Ray – Ray Wai Jul 29 '15 at 08:59

0 Answers0