Home  >  Article  >  Backend Development  >  PHP deletes a folder and all files under it_PHP tutorial

PHP deletes a folder and all files under it_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 10:34:191151browse

   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/752067.htmlTechArticlefunction deldir($dir) { $dh=opendir($dir); while ($file=readdir($dh)) { if($file!=. $file!=..) { $fullpath=$dir./.$file; if(!is_dir($fullpath)) { unlink($fullpath); } else { deldir...
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