<?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 "&nbsp;";
        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>";
}
?> 

解决方案 »

  1.   

    难看了点……./1.php
    ./py
        ./py/getpy.php
        ./py/py.dat
    ./2.php
    ./tv.html
    ./style.css
    ./tv.js
    ./3.php
    ./a.php
    ./upfiles
        ./upfiles/Note.txt
      

  2.   

    function PrintFileName($file, $nIndent) {
            echo "|-";
            for( $i=0; $i<$nIndent; $i++ )        echo "--";
            echo "<a href=\"$file\">".str_replace("./","",$file)."</a>";
            echo "<br>";
    }这样可以变得好看点.
      

  3.   

    我把$dirURL = ". " 改成了 $dirURL = "C:"结果程序只能显示几秒钟,然后就显示找不到服务器,是咋会事啊?