Here is the code I use to get an array of the files in a directory.
$dir = "thumbnails/";
$images = scandir($dir);
How can I sort the $images array by creation date? I found a couple of ways but I couldn't get any of them to work with my array.
Thanks,
On Windows you can get the creation time of the file with filectime(). Just put it in an array with the filename and sort the array.
Creation time is not stored on most *nix filesystems.
try the following tutorial that includes a script on how to sort by file modification/creation.
You have to sort manually
$dir = "thumbnails/";
function compare_time($a, $b)
{
global $dir;
$timeA = filectime("$dir/$a");
$timeB = filectime("$dir/$b");
if($timeA == $timeB) return 0;
return ($timeA < $timeB) ? -1 : 1;
}
$images = scandir($dir);
usort($images, 'compare_time');
Array([0] => '.', [1] => '..', [2] => 'afile.jpg');
have a look at php.net/scandirSaulo Vallory 2012-04-10 01:16