Php folder deletion, PHP clear cache program _php Tips

Source: Internet
Author: User
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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.