Home > Article > Backend Development > PHP deletes a folder and all files under it
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.