Page 1 of 1

Sort My Array, by date?

Posted: Mon Oct 10, 2005 7:43 am
by Blyant
I'm using this code that I put to gether to list the files in a directory on my server, it works just how I want it except that it returns the list of files in Numerical and alphabetical order. How do I sort the file list into the date order, the files were added to the server?

Code: Select all

<?php
echo "<?xml version=\"1.0\" encoding =\"ISO-8859-1\" ?>\n";
echo "<images>\n";
if ($handle = opendir('images')) {
   while (false !== ($file = readdir($handle))) {
       if ($file != "." && $file != "..") {
			list($width, $height) = getimagesize("images/".$file);
			echo "<myImage myPath=\"images/" . "$file\"" . " myWidth=\"" . "$width\"" . " myHeight=\"". "$height\"" ." />\n";
       }
   }
   closedir($handle);
}
echo "</images>\n"

?>

Posted: Mon Oct 10, 2005 7:59 am
by Jenk
Hi,

Use filectime() to get the time/date the file was created (this should also cover time of addition I think, as it is 'created'), also see fileatime and filemtime linked of the left of that there page.

HTH :)

Posted: Mon Oct 10, 2005 8:08 am
by Blyant
I'll give it ago, thank you for the help.