php delete directory and directory all files subdirectory

Source: Internet
Author: User
Keywords Network programming PHP tutorial
Tags be deleted delete delete directory deleted directory file files function

// php delete all files subdirectories under the directory and directory
/ *
This function is a use of recursive step by step to delete the files in the directory and all subdirectories of the current directory, oh, no matter the directory is not empty can be deleted,
* /
set_time_limit (0);
$ filenum = 0;
function deldir ($ dir) {
global $ filenum;
$ dh = opendir ($ dir);
while ($ file = readdir ($ dh)) {
if ($ file! = "." && $ file! = "..") {
$ fullpath = $ dir. "/". $ file;
if (! is_dir ($ fullpath)) {
unlink ($ fullpath);
if (($ filenum% 100) == 0) {
echo "*";
}
$ filenum = $ filenum + 1;
} else {
deldir ($ fullpath);
}
}
}
closedir ($ dh);
}
deldir ("/ www.jzread.com/");
echo "delete cache file success. total:". $ filenum;
?>

Related Article

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.