+ -
当前位置:首页 → 问答吧 → thinkphp 2.1清除缓存文件夹代码

thinkphp 2.1清除缓存文件夹代码

时间:2011-11-18

来源:互联网

/**
* 删除系统缓存
*/
function clearCache()
{
import("ORG.Io.Dir");
Dir::del(APP_PATH."/Runtime/");
Dir::del(APP_PATH."/Runtime/Cache/");
return 'succ';
}
//清除缓存文件夹
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;
  }
}
CacheAction.class.php代码如下
//清除缓存
public function cache() {
   deldir('admin/Runtime');
   $this->assign('waitSecond', 10);
   $this->success('缓存清理完毕!请刷新后台或者从新登陆!');
   $say= "清理缓存文件夹成功! "."</br>";
   $this->success($say);
    }

作者: dengwei1999   发布时间: 2011-11-18

写在哪?怎么用?我是新手,现在因为缓存不会清除,导致有些字段写不进去值。

作者: XX0604   发布时间: 2011-12-01