php删除目录及目录下所有文件子目录
本款函数是一款利用递归来一步步删除目录下文件与当前目录所有子目录,不管目录为不为空都可以删除,代码如下:
<?php
set_time_limit(0);
$filenum = 0;
function deldir($dir) {
global $filenum;
$dh = opendir($dir);
while ($file = readdir($dh)) {
if ($file != "." && $file != "..") {
$fullpath = $dir . "/" . $file;
if (!is_dir($fullpath)) {
unlink($fullpath);
if (($filenum % 100) == 0) {
echo "*";
}
$filenum = $filenum + 1;
} else {
deldir($fullpath);
}
}
}
closedir($dh);
}
deldir("/www.phprm.com/");
echo "delete cache file success. total:" . $filenum;文章网址:http://www.phprm.com/wenjian/fs4285.html
随意转载^^但请附上教程地址。