首页 > IT职业 > IT职场 > php 删除文件夹的实现代码
php没有一个具体的删除文件夹方法,下面是我自己的一段关于删除文件夹的代码:
function deldir($dir) {
//先删除目录下的文件:
//chmod($dir,0777);
$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;
}
}
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/4686/viewspace-2809517/ ,如需转载,请注明出处,否则将追究法律责任。