php(tp) 遞歸刪除緩存方法

/**
* 清空系統緩存,遞歸刪除文件夾
*/

public function cleanCache(){                                                      
            delFile(RUNTIME_PATH);
            Cache::clear(); 
            $this->success("操作完成!!!",U('Admin/Admin/index'));
            exit();
            return $this->fetch();
        }
function delFile($path,$delDir = FALSE) {
    if(!is_dir($path))
                return FALSE;       
    $handle = @opendir($path);
    if ($handle) {
        while (false !== ( $item = readdir($handle) )) {
            if ($item != "." && $item != "..")
                is_dir("$path/$item") ? delFile("$path/$item", $delDir) : unlink("$path/$item");
        }
        closedir($handle);
        if ($delDir) return rmdir($path);
    }else {
        if (file_exists($path)) {
            return unlink($path);
        } else {
            return FALSE;
        }
    }
}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章