Home > Article > Backend Development > PHP delete a folder and all files under the folder, _PHP tutorial
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)) {
unlink($fullpath);
} else {
>
closedir($dh);
//Delete the current folder:
if(rmdir($dir)) {
return true;
} else {
return false;
}
}
?>
http://www.bkjia.com/PHPjc/993269.htmlwww.bkjia.com
true
TechArticle