dedecms有清除緩存的功能于是下功夫去研究了一下,結果弄的我云里霧里,嗨....結果自己在網上查了一下,按照網站的自己寫了一個清除緩存的功能.
tp執行代碼:
- //是獲取要清楚的目錄和目錄所在的絕對路徑
- public function cache(){
- ////前臺用ajax get方式進行提交的,這里是先判斷一下
- 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>-->
|
新聞熱點
疑難解答
圖片精選