Monday 26 December 2011

Sorting files with php


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

Reset numbering for Screenshots Win+PrtSc

I was using today the screen shot functionality of Windows 8.1 Win Key + PrtSc How to reset the numbering?