thinkphp 实现清除缓存
dedecms有清除缓存的功能于是下功夫去研究了一下,结果弄的我云里雾里,嗨....结果自己在网上查了一下,按照网站的自己写了一个清除缓存的功能.
tp执行代码:
-
- public function cache(){
-
- if($_POST['type']){
-
- $type=$_POST['type'];
-
- $name=explode('-', $type);
-
- $count=count($name);
-
- for ($i=0;$i<$count;$i++){
-
- $abs_dir=dirname(dirname(dirname(dirname(__FILE__))));
-
- $pa=$abs_dir.'\index\Runtime\\';
- $runtime=$abs_dir.'\index\Runtime\~runtime.php';
- if(file_exists($runtime))
- {
- unlink($runtime);
- }
-
- $this->rmFile($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);
- }
- }
- }
tp:前台代码(有点简陋哦)
- <!--<html>
- <head>
- <title></title>
- <script language="javascript" type="text/javascript" src="__PUBLIC__/js/jquery.js"></script>
- <script type="text/javascript">
- $(function(){
- $('#button').click(function(){
- if(confirm("确认要清除缓存?")) {
- var $type=$('#type').val();
- var $mess=$('#mess');
- $.post('__URL__/cache',{type:$type},function(data){
- alert("缓存清理成功");
- });
- }else{
- return false;
- }
- });
- });
- </script>
- </head>
- <body>
- <!-- <table border="0" cellpadding="2" cellspacing="1" style="width:100%">
- <tr>
- <input type="hidden" name="type" id="type" class="text" style="width:50px" value="Cache-Data-Temp-Logs" />
- <td nowrap align="left"><input type="button" id="button" class="text" value="点击一键清除所有" /></td>
- <td id="mess"></td>
- </tr>
- </table>-->
- </body>-->