note 55442 added to function.readdir
| From: | Basis-basis dot klown-network dot com at osu1 dot php dot net | Date: | Wed, 03 Aug 2005 20:11:03 +0000 |
| Subject: | note 55442 added to function.readdir | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-93024@lists.php.net to get a copy of this message | ||
Alex's example was really good except for just one small part that was keeping it from
displaying directories above files in alphabetical order (His has makes the directories and files
mixed)
I changed 'if (is_dir($path.$file))' to 'if (is_dir($file))' and it works
perfectly now. Here's the whole block.
<code>
$path = $_SERVER[DOCUMENT_ROOT];
$dh = @opendir($path);
while (false !== ($file=@readdir($dh)))
{
if (substr($file,0,1)!=".")
{
if (is_dir($file))
$dirs[]=$file.'/';
else
$files[]=$file;
}
}
@closedir($dh);
if ($files)
natcasesort($files);
if ($dirs)
natcasesort($dirs);
$files=array_merge($dirs,$files);
foreach ($files as $file)
echo "<a href=$file>$file</a><br />";
</code>
----
Manual Page -- http://www.php.net/manual/en/function.readdir.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+55442
Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+55442&report=yes&reason=added+to+the+manual
Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+55442&report=yes&reason=bad+code
Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+55442&report=yes&reason=spam
Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+55442&report=yes&reason=useless
Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+55442&report=yes&reason=non-english
Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+55442&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+55442&report=yes
Search -- http://master.php.net/manage/user-notes.php