PHP Recursive Delete folder

Source: Internet
Author: User

Because PHP rmdir can only delete empty folders.

Once you delete a folder with files, you need to delete the files in the folder first.

Of course, there are folders in the folder, there are folders below .... How to do it.

Recursive deletion method to solve this problem perfectly. On the Code

functionRmfile ($dir){       if(!file_exists($dir))Echo"File does not exist!"; if($file _dir=Opendir($dir)) {             while(($sun _file=Readdir($file _dir)) !=false) {                if($sun _file!== '. ' &&$sun _file!== ' ... ') {                    if(Is_dir("$dir/$sun _file") {rmfile ("$dir/$sun _file"); } Else {                        unlink("$dir/$sun _file"); }                }            }        }        Closedir($file _dir); rmdir($dir);} Rmfile ("./dir");

This was written by myself, and one of the others wrote the same principle. can also refer to. It's best to write it all over again.

http://blog.csdn.net/wuxiaopeng_1986/article/details/52956870

PHP Recursive Delete folder

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.