thinkphp3.2 删除缓存文件

时间:2022-09-29 19:02:57
//删除后台缓存
public function ajaxcleanCache(){
   $dir = "./Application/Runtime/Logs/Admin/";
   if($this->deldir($dir)){
       echo 1;die;
   }else{
       echo 2;die;
   }

}
public function deldir($dir) {
    $dh = opendir($dir);
  //循环删除文件夹下所有的缓存文件
    while ($file = readdir($dh)) {
        if($file != "." && $file!="..") {
            $fullpath = $dir."/".$file;
            if(!is_dir($fullpath)) {
                unlink($fullpath);
            } else {
                deldir($fullpath);
            }
        }
    }
    closedir($dh);
    //删除当前文件夹:
    if(rmdir($dir)) {
        return true;
    } else {
        return false;
    }
}