function deldir($path){

      if(!is_dir($path)){

                  return false;

        }

    $dh = opendir($path);

   while(($file = readdir($dh)) !== false){

        if($file != '.' && $file != '..'){

              if(is_dir($file)){

                                                     mk_dir($file);

                  }else{

                      unlink($file);//删除所有子文件

                    }

            }

    }

          closedir($path); //只有关闭了目录才能删除

       rmdir($path);//只有清空了目录才能删除它本身

        echo '删除成功',$path,'<br/>';//只是一个测试 可以不加

       return true;

}

echo  deldir('./a')?'ok':'fail';

相关文章: