note 52129 added to function.is-dir
| From: | renich at woralelandia dot com | Date: | Thu, 21 Apr 2005 18:45:42 +0000 |
| Subject: | note 52129 added to function.is-dir | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-88369@lists.php.net to get a copy of this message | ||
Here goes a PHP5.0 link-to-directory listing function and examples
<?php
//List directories only
function list_dirs($path, $target)
{
$list = scandir($path);
foreach ($list as $number => $filename)
{
if ( $filename !== '.' && $filename !== '..' &&
is_dir("$path/$filename") )
{
// Asign more readable and logic variables
$dir = $filename;
$url = apache_request_headers();
if ($target == '')
{
// Print Dirs with link
print ("<a href=\"http://$url[Host]/$path/$dir\">$dir</a>
<br>\n");
}
else
{
// Print Dirs with link
print ("<a href=\"http://$url[Host]$dir\"
target=\"$target\">$dir</a> <br>\n");
}
}
}
}
?>
1.- List current directory's directories with no target property.
<?php
list_dirs('.','')
?>
2.- List "libraries" in "pma2" located at my dir with a "_blank"
target set
<?php
list_dirs('pma2/libraries','_blank');
?>
or
<?php
list_dirs('/var/www/html/pma2/libraries','_blank');
?>
3.- List all the directories located at the "/Home" dir with "_me" as target.
<?php
list_dirs('/home', ''_me');
?>
I hope you all like it!
Note:
Obviously, the links will now work if the're not in the apache dir... ("htdocs",
"html", "www", whatever)
----
Manual Page -- http://www.php.net/manual/en/function.is-dir.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+52129
Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+52129&report=yes&reason=added+to+the+manual
Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+52129&report=yes&reason=bad+code
Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+52129&report=yes&reason=spam
Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+52129&report=yes&reason=useless
Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+52129&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+52129&report=yes
Search -- http://master.php.net/manage/user-notes.php