Home  >  Article  >  Backend Development  >  PHP 删除文件夹及其文件夹下所有文件,_PHP教程

PHP 删除文件夹及其文件夹下所有文件,_PHP教程

WBOY
WBOYOriginal
2016-07-13 09:55:02937browse

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;
  }
}
?>

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/993269.htmlTechArticlePHP 删除文件夹及其文件夹下所有文件, ? functiondeldir($dir){ //先删除目录下的文件: $dh=opendir($dir); while($file=readdir($dh)){ if($file!="."$file!=".."...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn