级联删除

 1 function deleteDir($path){//没有检测目录是否存在
 2         $handle=opendir($path);
 3         while(false!==($file=readdir($handle))){
 4             if($file!='.'&&$file!='..'){
 5                 $subpath=$path.'/'.$file;
 6                 if(is_file($subpath)){
 7                     unlink($subpath);
 8                 }
 9                 if(is_dir($subpath)){
10                     deleteDir($subpath);
11                 }                     
12             }
13        }
14        closedir($handle);
15        return rmdir($path);
16 
17 }

15行是最后$path跳出时,从后面往前面删除

原文地址:https://www.cnblogs.com/fengyiqing/p/4058747.html