Heres a way to remove the directory, and all sub content.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;
}
}
$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;
}
}
$dh=opendir($dir);
while ($file=readdir($dh)) {
if($file!="." || $file!="..") {
return false;
}
}
return true;
}
if(IsDirEmpty($url))
rmdir($url);
else echo $url;
输出的文件夹明明为空,就是不执行删除操作,问题在那?
function IsDirEmpty($dir)
{
$dh=opendir($dir);
while ($file=readdir($dh))
{
if($file!="." && $file!="..")
return false;
}
return true;
}
提示我:
Warning: rmdir(../empty): Permission denied in D:\webroot\Manger\delFile.php on line 44为什么会拒绝删除啊?文件夹已经是空的了啊!
{
chmod($url1, 0777);
rmdir($url1);
}
或者
if(IsDirEmpty($url1))
{
@chmod($url1, 0777);
rmdir($url1);
}
同样出错啊???