Copy code The code is as follows:
header('content-type:text/html;charset=utf -8');
function delFile($fpath) {
$filesize = array();
$filepath = iconv('gb2312', 'utf-8', $fpath);
if (is_dir($fpath)) {
if ($dh = opendir($fpath)) {
while (($file = readdir($dh)) !== false) {
if( $file != '.' && $file != '..') {
$filesize[] = delFile($fpath.'/'.$file);
}
}
closedir($dh);
}
/*
* Convenient for counting the number of directories
*/
$filesize['file'] = 0;
if(@rmdir($ fpath) === true) {
echo "{$filepath}............Delete successfully
n";
} else {
echo "{$filepath}............delete failed
n";
}
} else {
if(is_file($ fpath)) {
$filesize[] = $fsize = filesize($fpath);
if(@unlink($fpath) === true) {
echo "{$filepath}... {$fsize}K............Delete successfully
n";
} else {
echo "{$filepath}...{$ fsize}K............Delete failed
n";
}
}
}
return $filesize;
}
/*
* function getArrSum(array &$arr) array sum
* array &$arr processed array
*/
function getArrSum(&$arr) {
if(is_array($arr)) {
foreach ($arr as &$value) {
$value = getArrSum($value);
}
return array_sum($arr);
} else {
return $arr;
}
}
$fpath = 'D:/test';
$filesize = delFile($fpath);
$size = getArrSum($filesize);
printf('Save you: %.3fM space', $size/(1024*1024));
?>
As long as Create a test folder under the D drive, and then copy anything into it to test.
http://www.bkjia.com/PHPjc/320552.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/320552.htmlTechArticleCopy the code as follows: ?php header('content-type:text/html;charset=utf-8' ); function delFile($fpath) { $filesize = array(); $filepath = iconv('gb2312', 'utf-8', $fpath); if (is...