Re: Unlimited Depth File Indexing
| From: | Joe Conway | Date: | Sat, 21 Oct 2000 17:38:50 +0000 |
| Subject: | Re: Unlimited Depth File Indexing | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-21575@lists.php.net to get a copy of this message | ||
> From: "Mukul Sabharwal" <mukulsabharwal@yahoo.com>
> To: <php-general@lists.php.net>
> Sent: Saturday, October 21, 2000 10:14 AM
> Subject: [PHP] Unlimited Depth File Indexing
> DirA, I want PHP to index all the files in it, go into
> subdirs if any, index all files of that, so on keep on
> going unltil reached.
Here's an example that will start at your document root, and recurse down 99
levels, creating a page of links to all php, asp, htm, and html files on
your site. Note that the 99 levels is arbitrary and is simply there as a
safety valve.
Hope this helps,
Joe
******************** begin dirwalk.php **************************
<?
function recursedirs($currentdir,$level) {
global $DOCUMENT_ROOT;
$newlevel = $level + 1;
if ($newlevel > 99) {
print "Too many levels!<br>\r\n";
exit;
}
if (substr(strrev($currentdir),0,1) != "/") {
$currentdir = $currentdir . "/";
};
$retval = @chdir($currentdir);
if ($retval != 1) {
return $currentdir . " skipped!";
};
$dhdl=opendir(".");
while ($filename = readdir($dhdl)) {
if(is_dir($filename)) {
$dlist[] = $filename;
}
if(is_file($filename)) {
$flist[] = $filename;
}
}
closedir($dhdl);
if($flist) {
while (list ($key, $filename) = each ($flist)) {
if (strtolower(substr($filename,strlen($filename)-4)) == ".php" ||
strtolower(substr($filename,strlen($filename)-5)) == ".html" ||
strtolower(substr($filename,strlen($filename)-4)) == ".asp" ||
strtolower(substr($filename,strlen($filename)-4)) == ".htm") {
print " <a href='" . str_replace($DOCUMENT_ROOT,"",$currentdir) .
$filename . "'>" . str_replace($DOCUMENT_ROOT,"",$currentdir) .
$filename .
"</a><br>\r\n";
};
};
};
if($dlist) {
while (list ($key, $filename) = each ($dlist)) {
if (!($filename == "." || $filename == "..")) {
$status = recursedirs($currentdir . $filename,$newlevel);
if ($status) {
print "<b><font color=red>" . $status .
"</font></b><br>\r\n";
}
};
};
};
return;
}
$level = 0;
print "<html><body>\r\n";
recursedirs($DOCUMENT_ROOT,$level);
print "</body></html>";
?>
******************** end dirwalk.php **************************