Copy Code 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_dir ($fpath)) {
if ($dh = Opendir ($fpath)) {
while (($file = Readdir ($DH))!== false) {
if ($file!= '. ' && $file!= ' ... ') {
$filesize [] = Delfile ($fpath. ' /'. $file);
}
}
Closedir ($DH);
}
/*
* Convenient Statistics Directory number
*/
$filesize [' file '] = 0;
if (@rmdir ($fpath) = = True) {
echo "{$filepath} ......... Delete successful <br>\n ";
} else {
echo "{$filepath} ......... Delete Failed <br>\n ";
}
} else {
if (Is_file ($fpath)) {
$filesize [] = $fsize = FileSize ($fpath);
if (@unlink ($fpath) = = True) {
echo "{$filepath} ... {$fsize} K................ Delete successful <br>\n ";
} else {
echo "{$filepath} ... {$fsize} K................ Delete Failed <br>\n ";
}
}
}
return $filesize;
}
/*
* Function Getarrsum (array & $arr) array summation
* Array & $arr processed arrays
*/
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 for You:%.3fm space ', $size/(1024*1024));
?>
Just set up a test folder under D, and then you can test it with a little bit of stuff in it.