thinkphp3.2删除Runtime缓存文件夹

本文介绍了一种使用PHP实现的系统缓存清理方法。通过定义public function del_cache()函数,可以实现对指定目录下的文件缓存进行清理。该方法首先设置页面字符集为UTF-8,然后定义要清理的目录,并尝试创建新目录以确保路径存在。接着遍历指定的目录,利用递归删除目录及其内容。最后,显示缓存清除成功的消息。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

public function del_cache() { 
 header("Content-type: text/html; charset=utf-8");
  //清文件缓存
  $dirs = array('./Runtime/');
  @mkdir('Runtime',0777,true);
  //清理缓存
  foreach($dirs as $value) {
   $this->rmdirr($value);
  }
  $this->assign("jumpUrl","__ROOT__/");
  $this->success('系统缓存清除成功!');
  //echo '<div style="color:red;">系统缓存清除成功!</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);
 }

文章来源:http://blog.sina.com.cn/s/blog_827ddd9501019ggl.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

撸猫@冒泡泡

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值