PHP iterates through and deletes all files in a folder

Source: Internet
Author: User

1<?PHP2   Header("Content-type:text/html;charset=utf-8");3   4   /**5 * Getdirfile traverse All files in the folder6 * @param $path7    */8   functionGetdirfile ($path){9     //determine if it is a folderTen     if(Is_dir($path)){ One         //deciding whether to open successfully A         if($handle=Opendir($path)){ -              -             //Read File the              while($file=Readdir($handle)){ -                 //determine if it is a folder -                 if(Is_dir($path.‘ /‘.$file) &&$file! = '. ' &&$file! = ' ... '){ -                     Echo' Folder: '.$file.‘ <br/> '; +Getdirfile ($path.‘ /‘.$file); -}Else { +                     if($file! = '. ' &&$file! = ' ... '){ A                         Echo' File: '.$file.‘ <br/> '; at                     } -                 } -             } -              -             //Close Folder -             Closedir($handle); in         } -     } to}

1 /**2 * RemoveDir Delete all files under folder3 * @param $path4    */5   functionRemoveDir ($path){6     //determine if it is a folder7     if(Is_dir($path)){8         //deciding whether to open successfully9         if($handle=Opendir($path)){Ten             //Read File One              while($file=Readdir($handle)){ A                 //determine if it is a folder -                 if(Is_dir($path.‘ /‘.$file.‘ /') &&$file! = '. ' &&$file! = ' ... '){ -RemoveDir ($path.‘ /‘.$file.‘ /‘); the}Else { -                     if($file! = '. ' &&$file! = ' ... '){ -                         //Deleting Files -                         unlink($path.‘ /‘.$file); +                     } -                 } +                  A             } at             //Close Folder -             Closedir($handle); -             //Delete a folder -             rmdir($path.‘ /‘.$file.‘ /‘); -         } -     } in}

PHP iterates through and deletes all files in a 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.