这篇文章主要介绍了ThinkPHP实现一键清除缓存方法,需要的朋友可以参考下
很多的开源cms系统都有一键清除缓存的功能,缓存是为了减轻服务器的压力而产生的,,但是同时有缓存的存在也可能使一些数据不能实时更新,对此,我们就来实现一个ThinkPHP的清理缓存的功能。代码如下:
ThinkPHP后台执行的代码:
//获取要清楚的目录和目录所在的绝对路径 public function cache(){ ////前台用ajax get方式进行提交的,这里是先判断一下 if($_POST['type']){ //得到传递过来的值 $type=$_POST['type']; //将传递过来的值进行切割,我是用“-”进行切割的 $name=explode('-', $type); //得到切割的条数,便于下面循环 $count=count($name); //循环调用上面的方法 for ($i=0;$irmFile($pa,$name[$i]); } //给出提示信息 $this->ajaxReturn(1,'清除成功',1); }else{ $this->display(); } } public function rmFile($path,$fileName){//删除执行的方法 //去除空格 $path = preg_replace('/(/){2,}|{}{1,}/','/',$path); //得到完整目录 $path.= $fileName; //判断此文件是否为一个文件目录 if(is_dir($path)){ //打开文件 if ($dh = opendir($path)){ //遍历文件目录名称 while (($file = readdir($dh)) != false){ //逐一进行删除 unlink($path.''.$file); } //关闭文件 closedir($dh); } } }
前台页面部分代码如下:

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool

SublimeText3 English version
Recommended: Win version, supports code prompts!

WebStorm Mac version
Useful JavaScript development tools

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.

Zend Studio 13.0.1
Powerful PHP integrated development environment