note 55442 deleted from function.readdir by tularis
| From: | tularis@php.net | Date: | Sun, 13 May 2007 19:03:02 +0000 |
| Subject: | note 55442 deleted from function.readdir by tularis | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-126527@lists.php.net to get a copy of this message | ||
Note Submitter: Basis - basis.klown-network.com
----
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>