php递归删除目录及子文件文件夹

$path='./phpMyAdmin';

function delAll($path){
    if(is_dir($path)){
        $handle=opendir($path);
        //$file=readdir($handle);        为什么不能在外面读取目录句柄        
        while(false !== ($file = readdir($handle))){
            if($file=='.' ||$file=='..'){
                continue;
            }
            if(is_dir($path.'/'.$file)){
                delAll($path.'/'.$file);
            }else{
                unlink($path.'/'.$file);    //删除文件
            }
        }
        closedir($handle);      //关闭目录句柄
        rmdir($path);           //删除空目录
    }else{
        echo "不是目录";
    }
}


delAll($path);

 

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