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); |
?>