thinkphp清空全部目錄(包括子目錄)

來源:互聯網
上載者:User
thinkphp清空所有目錄(包括子目錄)
在admin項目的Common目錄下common.php檔案:/***   刪除xml目錄下的所有xml檔案*   string $fp  檔案路徑(不包括檔案名稱)*   string $fn  檔案名稱(包括副檔名)*   boolean $type 是否關聯到所有子目錄*/function delXML($type=true,$fn='',$fp='./xml'){ if(!is_dir($fp)){  return 'nodir';  //被刪除目錄不存在 }else{  if(!is_empty_dir($fp)){//如果不是空的        $H = @ opendir($fp);   while(false !== ($_file=readdir($H))){    //檢索目錄    if(is_dir($fp."/".$_file) && $_file != "." && $_file!=".." && $_file!=="Thumbs.db"){     if($type){      if(!is_empty_dir($fp.'/'.$_file)){//如果不是,調用自身,不過是原來的路徑+他下級的目錄名          delXML($type,$fn,$fp."/".$_file);      }         if(is_empty_dir($fp.'/'.$_file)){//如果是空就直接刪除          rmdir($fp.'/'.$_file);         }        }    //檢索檔案    }else if(is_file($fp."/".$_file) && $_file!="." && $_file!=".." && $_file!=="Thumbs.db"){     if(eregi('/'.$file,'/'.$_file)){      if(!unlink($fp.'/'.$_file)){       return false; //刪除失敗      }     }    }   }   closedir($H);    }     return true;   //刪除失敗 }}   //判斷目錄是否為空白,true為空白,false為不空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;   }} 調用方法:在admin項目的Action目錄下SiteMapAction.class.php檔案:class SiteMapAction extends Action { //刪除全部xml目錄地圖檔案 function delXML(){  $flag = delXML();  exit($flag); }} 靜態頁面ajax方法:刪除目錄檔案

?

  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    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.