Php folder deletion, php clearing cache program _ PHP Tutorial

Source: Internet
Author: User
Delete php folders and clear cache programs in php. Copy the code as follows :? Phpheader (content-type: texthtml; charsetutf-8); functiondelFile ($ fpath) {$ filesizearray (); $ filepathiconv (gb2312, UTF-8, $ fpath); if (is 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 statistics on the number of directories
*/
$ Filesize ['file'] = 0;
If (@ rmdir ($ fpath) === true ){
Echo "{$ filepath}... deleted successfully.
\ N ";
} Else {
Echo "{$ filepath} ...... deletion failed.
\ N ";
}
} Else {
If (is_file ($ fpath )){
$ Filesize [] = $ fsize = filesize ($ fpath );
If (@ unlink ($ fpath) === true ){
Echo "{$ filepath}... {$ fsize} K ...... deleted successfully
\ N ";
} Else {
Echo "{$ filepath}... {$ fsize} K ...... deletion failed
\ N ";
}
}
}
Return $ filesize;
}
/*
* Function getArrSum (array & $ arr) array summation
* 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 for you: %. 3fM space', $ size/(1024*1024 ));
?>


You just need to create a test folder under drive D, and then just pull something into it to test it.

The http://www.bkjia.com/PHPjc/320552.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/320552.htmlTechArticle code is as follows :? Php header ('content-type: text/html; charset = utf-8 '); function delFile ($ fpath) {$ filesize = array (); $ filepath = iconv ('gb2312', 'utf-8', $ fpath); if (is...

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.