Home > Backend Development > PHP Tutorial > PHP folder deletion, PHP cache clearing program_PHP tutorial

PHP folder deletion, PHP cache clearing program_PHP tutorial

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-07-21 15:44:22
Original
1170 people have browsed it

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.

www.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...
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Issues
php data acquisition?
From 1970-01-01 08:00:00
0
0
0
PHP extension intl
From 1970-01-01 08:00:00
0
0
0
How to learn php well
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template