-1

I use this code to load images from folder:

$dirname = "media/images/iconized/";
$images = glob($dirname."*.png");

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

Source: Pull all images from a specified directory and then display them

Works perfect. But load images in alphabetic order (A-Z). My question is:

How to load images from folder by modification date or creation date? To get newest first.

Greetings.

Luis
  • 21
  • 3

1 Answers1

0

Look at this solution:

https://stackoverflow.com/a/125047/4173464

<?php

$dirname = "media/images/iconized/";
$images = glob($dirname."*.png");
usort( $images, function( $a, $b ) { return filemtime($a) - filemtime($b); } );

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

?>
db1975
  • 775
  • 3
  • 9