/**
* 删除文件夹
* @param string $dir 目录路径
* @param boolean $delDir 是否删除路径文件夹
* @return int 单位bytes
*/
function unDir($dir, $delDir = true)
{
$i = 0;
$dh = opendir($dir);
while ($file = readdir($dh)) {
if ('.' != $file && '..' != $file) {
$fullpath = $dir . '/' . $file;
if (!is_dir($fullpath)) {
if (unlink($fullpath)) {
$i++;
}
} else {
$i += undir($fullpath);
}
}
}
closedir($dh);
if ($delDir) {
rmdir($dir);
}
return $i;
}