note 70479 added to function.readdir
| From: | dot) | Date: | Wed, 18 Oct 2006 13:23:00 +0000 |
| Subject: | note 70479 added to function.readdir | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-118686@lists.php.net to get a copy of this message | ||
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";
?>
----
Server IP: 192.35.244.50
Probable Submitter: 83.215.146.135
----
Manual Page -- http://www.php.net/manual/en/function.readdir.php
Edit -- https://master.php.net/note/edit/70479
Del: integrated -- https://master.php.net/note/delete/70479/integrated
Del: useless -- https://master.php.net/note/delete/70479/useless
Del: bad code -- https://master.php.net/note/delete/70479/bad+code
Del: spam -- https://master.php.net/note/delete/70479/spam
Del: non-english -- https://master.php.net/note/delete/70479/non-english
Del: in docs -- https://master.php.net/note/delete/70479/in+docs
Del: other reasons-- https://master.php.net/note/delete/70479
Reject -- https://master.php.net/note/reject/70479
Search -- https://master.php.net/manage/user-notes.php