note 71183 added to function.filectime
| From: | StevieMc at example dot com | Date: | Wed, 15 Nov 2006 14:28:49 +0000 |
| Subject: | note 71183 added to function.filectime | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-119749@lists.php.net to get a copy of this message | ||
This method gets all the files in a directory, and echoes them in the order of the date they were
added (by ftp or whatever).
<?PHP
function dirList ($directory, $sortOrder){
//Get each file and add its details to two arrays
$results = array();
$handler = opendir($directory);
while ($file = readdir($handler)) {
if ($file != '.' && $file != '..' && $file !=
"robots.txt" && $file != ".htaccess"){
$currentModified = filectime($directory."/".$file);
$file_names[] = $file;
$file_dates[] = $currentModified;
}
}
closedir($handler);
//Sort the date array by preferred order
if ($sortOrder == "newestFirst"){
arsort($file_dates);
}else{
asort($file_dates);
}
//Match file_names array to file_dates array
$file_names_Array = array_keys($file_dates);
foreach ($file_names_Array as $idx => $name) $name=$file_names[$name];
$file_dates = array_merge($file_dates);
$i = 0;
//Loop through dates array and then echo the list
foreach ($file_dates as $file_dates){
$date = $file_dates;
$j = $file_names_Array[$i];
$file = $file_names[$j];
$i++;
echo "File name: $file - Date Added: $date. <br/>"";
}
}
?>
I hope this is useful to somebody.
----
Server IP: 82.146.33.222
Probable Submitter: 217.155.198.148
----
Manual Page -- http://www.php.net/manual/en/function.filectime.php
Edit -- https://master.php.net/note/edit/71183
Del: integrated -- https://master.php.net/note/delete/71183/integrated
Del: useless -- https://master.php.net/note/delete/71183/useless
Del: bad code -- https://master.php.net/note/delete/71183/bad+code
Del: spam -- https://master.php.net/note/delete/71183/spam
Del: non-english -- https://master.php.net/note/delete/71183/non-english
Del: in docs -- https://master.php.net/note/delete/71183/in+docs
Del: other reasons-- https://master.php.net/note/delete/71183
Reject -- https://master.php.net/note/reject/71183
Search -- https://master.php.net/manage/user-notes.php