thinkphp empty all directories (including subdirectories)

Source: Internet
Author: User
thinkphp Clear all directories (including subdirectories)
common.php file in the common directory of the admin project:/*** Delete all XML files under XML directory * string $fp file path (not including file name) * String $FN file name (including extension) * Boolean $  Whether the type is associated to all subdirectories */function delxml ($type =true, $fn = ', $fp = './xml ') {if (!is_dir ($fp)) {return ' Nodir ';   The deleted directory does not exist}else{if (!is_empty_dir ($fp)) {//If it is not empty $H = @ opendir ($FP); while (False!== ($_file=readdir ($H))) {//retrieves the directory if (Is_dir ($fp. " /". $_file) && $_file! =". "&& $_file!=": "&& $_file!==" Thumbs.db ") {if ($type) {if"!is_e Mpty_dir ($fp. '/'. $_file)} {//If not, call itself, but the original path + his subordinate directory name Delxml ($type, $FN, $fp. "      /". $_file);         } if (Is_empty_dir ($fp. '/'. $_file)) {//If it is empty, delete the rmdir ($fp. '/'. $_file); }}//Retrieve file}else if (Is_file ($fp. " /". $_file) && $_file!=". "&& $_file!=": "&& $_file!==" Thumbs.db ") {if (eregi ('/') $file, '/'. $_    File) {if (!unlink ($fp. '/'. $_file)) {return false;//delete Failed}}}} Closedir ($H);   } return true;  Delete Failed}} Determines whether the directory is empty, true is null, false is not empty function Is_empty_dir ($fp) {$H = @ opendir ($fp); $i = 0;    while ($_file=readdir ($H)) {$i + +;    } closedir ($H); if ($i >2) {return false;}   else{return true; }} Call method: SiteMapAction.class.php file under the action directory of the Admin project: Class Sitemapaction extends Action {//delete all XML directory map file function  Delxml () {$flag = Delxml (); Exit ($flag); }} Static page Ajax method:
 
  
 <title>Delete a catalog file</title>

?

  • 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.