代碼如下:
private function _deleteDir($R)
{
$handle = opendir($R);
while(($item = readdir($handle)) !== false){
if($item != '.' and $item != '..'){
if(is_dir($R.'/'.$item)){
$this->_deleteDir($R.'/'.$item);
}else{
if(!unlink($R.'/'.$item))
die('error!');
}
}
}
closedir( $handle );
return rmdir($R);
}
public function clearRuntime()
{
$R = $_GET['path'] ? $_GET['path'] : RUNTIME_PATH;
if($this->_deleteDir($R))
die("cleared!");
}使用說明:將上面這兩個方法放入到你的管理後台的控制器裡面,然後瀏覽器進入clearRuntime操作即可。
支持通過get傳值刪除你想刪的文档夾(注意別把有用的目錄刪掉,如果想刪掉整個網站可以輸入 ./ 哈哈~)