php递归遍历目录

$path='./phpMyAdmin';

function showAll($path){
    if(is_dir($path)){
        $handle=opendir($path);
        //$file=readdir($handle);        为什么不能在外面读取目录句柄
        echo "<ul>";        
        while(false !== ($file = readdir($handle))){
            if($file=='.' ||$file=='..'){
                continue;
            }
            echo "<li>".$file."</li>";
            if(is_dir($path.'/'.$file)){
                showAll($path.'/'.$file);
            }
        }
        echo "</ul>";
        closedir($handle);//关闭目录句柄
    }else{
        echo "不是目录";
    }
}

showAll($path);

 

posted @ 2017-11-02 22:17  za_szybko  阅读(270)  评论(0编辑  收藏  举报