note 70479 deleted from function.readdir by tularis
| From: | tularis@php.net | Date: | Sun, 13 May 2007 18:59:16 +0000 |
| Subject: | note 70479 deleted from function.readdir by tularis | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-126502@lists.php.net to get a copy of this message | ||
Note Submitter: suit (at) rebell (dot) at
----
better version of the yesterdays script
first it reads all content and divides it into files and directorys (two arrays)
then the arrays will be sorted and an output is given (directorys first, then the files)
<?php
$startdir = "downloads/";
$dir = "$startdir$subdir";
echo "<table border=\"1\">\n";
echo "<tr>\n";
echo "<td><a href=\"directory.php\">UP ..</a></td>";
echo "<td>$subdir</td>";
echo "</tr>\n";
$array_dir = array();
$array_file = array();
if (is_dir($dir)) {
if ($dh = opendir($dir)) {
while (($file = readdir($dh)) !== false)
{
$filename = $file;
$filetype = filetype($dir . $file);
if ($filename == ".." OR $filename == ".")
{
echo "";
}
else
{
if ($filetype == "file")
{
$array_file[] = $filename;
}
elseif ($filetype == "dir")
{
$array_dir[] = $filename;
}
}
}
closedir($dh);
}
}
sort($array_dir);
foreach ($array_dir as $item) {
$subdir_n = "$subdir$item/";
echo "<tr>\n";
echo "<td>dir</td>\n";
echo "<td><a
href=\"directory.php?subdir=$subdir_n\">$item</a></td>\n";
echo "</tr>\n";
}
sort($array_file);
foreach ($array_file as $item) {
$subdir_n = "$subdir$item/";
echo "<tr>\n";
echo "<td>file</td>\n";
echo "<td>$item</td>\n";
echo "</tr>\n";
}
echo "</table>\n";
?>