<?php$dirURL = '.'; //base direction, related url
$nIndInc = 4; //the num of indent
TravelDir($dirURL);function TravelDir( $dirURL, $nIndent=0 ) {
global $nIndInc;
if ($handle = opendir($dirURL)) {
while (false !== ($file = readdir($handle))) {
if ($file != "." && $file != "..") {
$wholeFileName = $dirURL."/".$file;
if (is_dir($wholeFileName)) {
PrintFileName($wholeFileName, $nIndent);
TravelDir($wholeFileName,$nIndent+$nIndInc);
} else if (is_file($wholeFileName)) {
PrintFileName($wholeFileName, $nIndent);
} else {
PrintErr($file);
}
}
}
}
}function PrintFileName($file, $nIndent) {
for( $i=0; $i<$nIndent; $i++ ) echo " ";
echo "<a href=\"$file\">".$file."</a>";
echo "<br>";
}
function PrintErr($file) {
echo "<font color=red>error :</font> {$file}! Maybe the program is something wrong!<br>";
}
?>
$nIndInc = 4; //the num of indent
TravelDir($dirURL);function TravelDir( $dirURL, $nIndent=0 ) {
global $nIndInc;
if ($handle = opendir($dirURL)) {
while (false !== ($file = readdir($handle))) {
if ($file != "." && $file != "..") {
$wholeFileName = $dirURL."/".$file;
if (is_dir($wholeFileName)) {
PrintFileName($wholeFileName, $nIndent);
TravelDir($wholeFileName,$nIndent+$nIndInc);
} else if (is_file($wholeFileName)) {
PrintFileName($wholeFileName, $nIndent);
} else {
PrintErr($file);
}
}
}
}
}function PrintFileName($file, $nIndent) {
for( $i=0; $i<$nIndent; $i++ ) echo " ";
echo "<a href=\"$file\">".$file."</a>";
echo "<br>";
}
function PrintErr($file) {
echo "<font color=red>error :</font> {$file}! Maybe the program is something wrong!<br>";
}
?>
./py
./py/getpy.php
./py/py.dat
./2.php
./tv.html
./style.css
./tv.js
./3.php
./a.php
./upfiles
./upfiles/Note.txt
echo "|-";
for( $i=0; $i<$nIndent; $i++ ) echo "--";
echo "<a href=\"$file\">".str_replace("./","",$file)."</a>";
echo "<br>";
}这样可以变得好看点.