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

PHP deletes a folder and all files under it

WBOY
WBOYOriginal
2016-08-08 09:25:041019browse


function deldir($dir) {
//Delete the files in the directory first:
$dh=opendir($dir);
while ($file=readdir($ dh)) {
if($file!="." && $file!="..") {
$fullpath=$dir."/".$file;
if(!is_dir ($fullpath)) {
                                                                                                         }
}
closedir($dh) ;
//Delete the current folder:
if(rmdir($dir)) {
  return true;
} else {
  return false;
}
}
?>
The above introduces PHP to delete a folder and all files under the folder, including the content. I hope it will be helpful to friends who are interested in PHP tutorials.

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