Use filetime to get the last modified time for the file, like so:
$lastmodified = filemtime($filename);
instead of outputting straight away, write your data to an array first which can then be sorted. use the $lastmodified timestamp as your array keys, and you can sort on that.
Code:
<?php
$path = "/home/user/public/foldername/";
$dir_handle = @opendir($path) or die("Unable to open $path");
$filearray=array();
while ($file = readdir($dir_handle)) {
if($file == "." || $file == ".." || $file =="index.php" ) continue;
// get the modified dat as as timestamp
$lastmodified = filemtime($path.$file);
// add to the array using the timestamp as a key
$filearray[$lastmodified]=$file;
}
// Close
closedir($dir_handle);
//sort the array in reverse order by the timestamp key
krsort($filearray);
foreach($filearray as $file){
echo "<a href=\"$file\">$file</a><br />";
}
All the best,
kinnon