This function will sort files in the directory passed as arguments by the last modified or created time
function sortFilesByDate($dirname)
{
clearstatcache();
$files = array();
if ($handle = opendir($dirname))
{
while (false !== ($file = readdir($handle)))
{
if ($file != "." && $file != "..")
{
$files[filemtime($dirname."/".$file)] = $file;
}
}
closedir($handle);
}
// sort
ksort($files);
end($files);
$tot = count($files);
$i = 0;
$EXITSTR = "";
while ($tot != $i)
{
$EXITSTR = $EXITSTR . current($files);
prev($files);
$i ++;
$EXITSTR = $EXITSTR . "<br/>";
}
return $EXITSTR;
}
No comments:
Post a Comment