List directory contents by date
Loads the contens of a dir an sorts them by the date of creation.
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; }
Author:
Jonas John
License:
Public Domain
Language:
PHP
Created:
03/29/2006
Updated:
03/29/2006
Tags:
directory functions, folder, files
listdir_by_date('data/');
Sorry folks, comments have been deactivated for now due to the large amount of spam.
Please try to post your questions or problems on a related programming board, a suitable mailing list, a programming chat-room,
or use a QA website like stackoverflow because I'm usually too busy to answer any mails related
to my code snippets. Therefore please just mail me if you found a serious bug... Thank you!
Older comments:
$file = '*';
$dir = '/path/to/wherever/';
$sorted_array = listdir_by_date($dir.$file);
function listdir_by_date($pathtosearch)
{
foreach (glob($pathtosearch) as $filename)
{
$file_array[filectime($filename)]=basename($filename); // or just $filename
}
ksort($file_array);
return $file_array;
}
works fine for me
you can print the list by making a for loop or just by print_r($list)
so i basically did this as a test to see if it works
$path = '../upload/pubvoyages/';//$_SERVER['DOCUMENT_ROOT'] . '/fr/pubvoyages/';
$list = listdir_by_date($path);
print_r ($list);
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($path . $file) . ',' . $file;
$list[$ctime] = $file;
}
}
closedir($dir);
krsort($list);
return $list;
}
$ctime = filectime($data_path . $file) . ',' . $file;
???