php删除文件夹及其文件夹下所有文件

简介:

<?


function deldir($dir) {


  //先删除目录下的文件:


  $dh=opendir($dir);


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


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


      $fullpath=$dir."/".$file;


      if(!is_dir($fullpath)) {


          unlink($fullpath);


      } else {


          deldir($fullpath);


      }


    }


  }


 


  closedir($dh);


  //删除当前文件夹:


  if(rmdir($dir)) {


    return true;


  } else {


    return false;


  }


}


本文转自 IT阿飞 51CTO博客,原文链接:http://blog.51cto.com/itafei/1757285
相关文章
|
1月前
thinkphp5.1隐藏index.php入口文件
thinkphp5.1隐藏index.php入口文件
30 0
thinkphp5.1隐藏index.php入口文件
|
3月前
|
PHP 数据安全/隐私保护
php案例:判断这个文件是什么编程语言代码的文件(判断java或者php)
php案例:判断这个文件是什么编程语言代码的文件(判断java或者php)
php案例:判断这个文件是什么编程语言代码的文件(判断java或者php)