zoukankan      html  css  js  c++  java
  • Thinkphp清除缓存文件

    Thinkphp的缓存在开发中是非常烦人的,因为有的时候因为缓存的问题而出现的错误是非常难找的。删除缓存更是麻烦,还要去文件夹下删除、如果是linux开发服务器的话还要登陆服务器进行删除。所以这个时候用php命令删除Thinkphp的缓存是非常不错的选择。

    代码: CacheAction.class.php

    class CacheAction extends CommonAction{
      //前台页面
      public function home(){
         header("Content-type: text/html; charset=utf-8");
         //清文件缓存
         $dirs = array('home/Runtime/');
         @mkdir('Runtime',0777,true);
         //清理缓存
         foreach($dirs as $value) {
          $this->rmdirr($value);
         }
         echo '<div >系统缓存清除成功!</div>';  
      }
     
     
     
      //后台页面
      public function admin(){
         header("Content-type: text/html; charset=utf-8");
         //清文件缓存
         $dirs = array('admin/Runtime/');
         @mkdir('Runtime',0777,true);
         //清理缓存
         foreach($dirs as $value) {
          $this->rmdirr($value);
         }
         echo '<div >系统缓存清除成功!</div>';  
      }
     
     
     
     
     
     
     
      //处理方法
       public function rmdirr($dirname) {
        if (!file_exists($dirname)) {
         return false;
        }
        if (is_file($dirname) || is_link($dirname)) {
         return unlink($dirname);
        }
        $dir = dir($dirname);
        if($dir){
         while (false !== $entry = $dir->read()) {
       if ($entry == '.' || $entry == '..') {
        continue;
       }
       //递归
       $this->rmdirr($dirname . DIRECTORY_SEPARATOR . $entry);
         }
        }
        $dir->close();
        return rmdir($dirname);
       }
     }
    ?>
  • 相关阅读:
    Asp.net开发必备51种代码
    防止页面被多次提交
    c#发送邮件.net1.1和.net2.0中的两个方法
    鼠标移至小图,自动显示相应大图
    NET(C#)连接各类数据库集锦
    在C#中对XML的操作
    Window.ShowModalDialog使用总结
    SQLServer2005 添加用户,及操作权限
    定时器
    Global.asax.cs中的方法的含义
  • 原文地址:https://www.cnblogs.com/Lance--blog/p/4472160.html
Copyright © 2011-2022 走看看