Sorting image files using server modifed date. Not File EXIF modified

I have been told to rewrite my question by Stackoverflow

I upload images mostly to a directory on my sever where my website is hosted. Via a program on my PC and a app on phone and that works a treat.

I have come across PHP scripts that shows all the images in the above folder and returns a basic gallery, and they all work to a point.

What I am hoping to achieve (it might not be possible) is list the images by the date they were added to the server. Not sorting from the EXIF modified date.

If it cant be done, so be it.

Best regards,


PS At the moment I’m use PHP Gallery, its OK but does not quite achive the sorting requirement I would like.

Gallery here.

Is it possible to display the contents of server folder (images) but sort by Last Modified ? using PHP

My very basic script:
$images = glob('img/*');

foreach ($images as $image) {
  echo '<img src="'.$image.'"><br>';

Link its used on.


This will sort the images by last modified time

$files = glob('img/*');

$output = [];

foreach ($files as $f) 
    $output[filemtime($f)] = $f;
$images = array_reverse($output);

foreach ($images as $image) 
    echo '<img src="' . $image . '"><br />';