help sorting readdir values
| From: | dan radom | Date: | Mon, 28 Jan 2002 16:49:34 +0000 |
| Subject: | help sorting readdir values | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-82433@lists.php.net to get a copy of this message | ||
First I must state that I didn't write the code, and I'm not much of a programmer of any
kind. I'm hoping someone can tell me how to sort the filenames and file sizes returned by
readdir and filesize in the below code. Thanks in advance.
dan
<?
function list_dir($dir)
{
$handle=opendir($dir);
echo "<ul>";
while ($file = readdir($handle))
{
if ($file != '.' && $file != '..' &&
!ereg("\.php$", $file)) {
print ("<tr>\n<td>\n");
print ("<li><a
href=\"".$GLOBALS["path"].$file."\">".$file."</a>");
print ("</td>\n");
if (is_dir($file))
{
printf ("<td>");
$toto = $GLOBALS["path"];
$GLOBALS["path"] .= $file."/";
chdir ($file);
list_dir(".");
$GLOBALS["path"] = $toto;
chdir ("..");
printf ("</td>");
} else {
printf ("<td>\n");
$size = filesize($file);
if ($size == NULL)
$size = "<unknown>";
printf (" ".$size."
bytes\n");
printf ("</td>\n");
}
print ("</tr>\n");
}
}
echo "</ul>";
closedir($handle);
}
$directory = "screenshots";
$GLOBALS["path"] = "http://".$HTTP_HOST."/".$directory."/";
echo "<table>\n";
list_dir(".");
echo "</table>";
?>