除 removeIt 之一(空白页)外,所有功能均有效。这是我的代码如下:
class Dir {
public function emptyIt($path) {
if ($handle = opendir($path)) {
while (false !== ($file = readdir($handle))) {
if ($file != "." && $file != "..") {
if(is_file($path."/".$file)) {
unlink($path."/".$file);
} else {
if($handle2 = opendir($path."/".$file)) {
while (false !== ($file2 = readdir($handle2))) {
if ($file2 != "." && $file2 != "..") {
unlink($path."/".$file."/".$file2);
}
}
}
rmdir($path."/".$file);
}
}
}
}
return true;
}
function isEmpty($path) {
$handle=opendir($path);
$i=0;
while (false !== ($file = readdir($handle))) {
$i++;
}
closedir($handle);
if($i>=2) {
return false;
} else {
return true;
}
}
public function removeIt($path) {
if (emptyIt($path)) {
if (rmdir($path)) {
return true;
} else {
return false;
}
}
}
}
我有 3 个功能可以让它工作:
isEmpty
: 验证文件夹是否为空emptyIt
: 空文件夹和子文件夹removeIt
: 删除文件夹
有什么提示吗?