PHP Displays all directories under the Web directory and filename with php,php3,htm,html suffix

Source: Internet
Author: User
Tags ereg

The first file name is Phplist.inc

The code is as follows Copy Code
?
Global $htmlroot;
$htmlroot = "/web/html"; "/web/html" is the Apache document root directory that users can modify according to their own configuration
?>

The second file name is codeshow.php

The code is as follows Copy Code
?
Highlight_file ($filename); Highlight file Code
?>

This is the main program named phplist.php

The code is as follows Copy Code
?
Require ("Phplist.inc");
if ($rootpath = = "") {$rootpath = $htmlroot;}
function FileList ($pathname) {//Traverse all files and directories, $pathnam as the starting directory, $searchs for search keywords
Global $htmlroot;
if (Eregi ("[/][.] [.] $ ", $pathname)) {
$temp =split ("[/]", $pathname);
$pathname = "";
For ($tt =1 $tt < (count ($temp)-2); $tt + +)
$pathname = $pathname. " /". $temp [$tt];
}
echo $pathname. "
";
$handle =opendir ($pathname); Open Directory
if (@chdir ($pathname)) {//CD Enter directory, do not enter if no permission
$file = Readdir ($handle); read out all the element names in the current directory for the first time read as '. ', refers to the upper directory
while ($file = Readdir ($handle)) {//If an element is to be handled as follows
$fname = $pathname. " /". $file; Combines the element name with the current directory name to form a complete file name and assigns it to the $fname
if (Is_file ($file)) and (Ereg (". php[3]{0,1}$", $file) or Ereg (". htm[l]{0,1}$", $file))//Determine whether to be a file and whether to end with. PHP and. php3
{
$TEMPPP =split ($htmlroot, $fname);
echo "<a href= $temppp [1]>". $file. " </a> ". FileSize ($file)." Bytes <a href=codeshow?filename= $fname ><font size=-1> source Files </font></a>
";
Findinfile ($fname, $searchs); Calling the Findinfile function
}
ElseIf (Is_dir ($fname)) {//To determine whether the directory
Linkres ($fname);
FileList ($fname, $searchs);} Recursive call filelist function
}
}
ChDir (".."); End current recursion, return to upper level
}
Closedir ($handle); Turn off current directory read
}
//
function Linkres ($filename) {
$tpath =split ("/web/html", $filename);
$turepath = $tpath [1];
Ereg ("[^\/~]{0,}$", $filename, $res);
$ft =filetitle ($filename);
if ($ft = = "") $ft = "Untitled";
echo "<a href=phplist.php?rootpath= $filename >". $res [0]. " </a> <dir>
";
}
//
FileList ($rootpath);

?>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.