List directory contents by date

Submitted by:Tim Kelly

Date added:30 August, 2015

Category:PHP

Loads the contents of a dir an sorts them by the date of creation.

Tags: load content , content by date

Code Snippet:

function listdir_by_date($path){
$dir = opendir($path);
$list = array();
while($file = readdir($dir)){
if ($file != '.' and $file != '..'){
// add the filename, to be sure not to
// overwrite a array key
$ctime = filectime($data_path . $file) . ',' . $file;
$list[$ctime] = $file;
}
}
closedir($dir);
krsort($list);
return $list;
}
 
 

Comments