ITPub博客

首页 > IT职业 > IT职场 > php 删除文件夹的实现代码

php 删除文件夹的实现代码

IT职场 作者:dead_lee 时间:2021-09-09 09:19:49 0 删除 编辑

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/ ,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论

注册时间:2021-06-25

  • 博文量
    82
  • 访问量
    15431