<?php
function ListFiles($directory,$order) {
$filearray = array ();
if ($dirh = opendir($directory)) {
while (($files = readdir($dirh)) !== FALSE) {
if ($files != "." and $files != "..") {
array_push($filearray,"<li><a target=\"_blank\" href=\"$directory/$files\">$files</a></li>\n");
}
}}
natsort($filearray);
if ($order == '' or $order == 'ASC') {
return $filearray;
} elseif ($order == 'DESC') {
return array_reverse($filearray);
}
}
// usage, directory name and order ASC or DESC
$filelist = ListFiles('logs','DESC');
echo "<div class='filelist'>\n";
foreach ($filelist as $x) {
echo $x;
}
echo "</div>";
?>