note 51267 added to function.scandir
| From: | brodseba at brodseba dot com | Date: | Fri, 25 Mar 2005 04:53:32 +0000 |
| Subject: | note 51267 added to function.scandir | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-86930@lists.php.net to get a copy of this message | ||
This function create a HTML view of a directory. It also look for subdirectory. I use some icon to
differ from folders or files. It's also possible to get specific icon for specific file type.
Each entrey is clickable so you can use it to populate a form field.
Have fun!
function ls_recursive2($dir)
{
if (is_dir($dir))
{
$files = scandir($dir);
foreach ($files as $file)
{
$currentfile = $dir . "/" . $file;
$last_dir = "";
// Calculate they identation.
$count = substr_count($currentfile, '/');
$minus_count = substr_count($_SERVER['DOCUMENT_ROOT'], '/');
$count -= ($minus_count + 2);
for($p = 0; $p < $count; $p++)
{
$last_dir .= " ";
}
if (is_dir($currentfile))
{
if ($file != '.' && $file != '..')
{
$last_dir .= "<img src='images/folder.gif' alt=''
align='middle' width='16' height='16'
border='0'> <a href=\"javascript:go('" . $currentfile .
"')\">". substr($currentfile, strrpos($currentfile, '/')) .
"</a><br>";
echo $last_dir;
ls_recursive2($currentfile);
}
}
else
{
$last_dir .= "<img src='images/file.gif' alt=''
align='middle' width='16' height='16'
border='0'> <a href=\"javascript:go('" . $currentfile .
"')\">". substr($currentfile, strrpos($currentfile, '/')) .
"</a><br>";
echo $last_dir;
}
}
}
}
----
Manual Page -- http://www.php.net/manual/en/function.scandir.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+51267
Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+51267&report=yes&reason=added+to+the+manual
Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+51267&report=yes&reason=bad+code
Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+51267&report=yes&reason=spam
Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+51267&report=yes&reason=useless
Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+51267&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+51267&report=yes
Search -- http://master.php.net/manage/user-notes.php