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;
}
} 
本文介绍了一个用于PHP的递归函数,该函数能够遍历指定目录并删除其中的所有文件和子目录,最终移除该目录。适用于需要清理整个目录结构的场景。
1万+

被折叠的 条评论
为什么被折叠?



