thinkphp 一鍵清除緩衝方法代碼

來源:互聯網
上載者:User
  1. //擷取要清楚的目錄和目錄所在的絕對路徑
  2. public function cache(){
  3. ////前台用ajax get方式進行提交的,判斷下
  4. if($_POST['type']){
  5. //得到傳遞過來的值
  6. $type=$_POST['type'];
  7. //將傳遞過來的值進行切割,我是用“-”進行切割的
  8. $name=explode('-', $type);
  9. //得到切割的條數,便於下面迴圈
  10. $count=count($name);
  11. //迴圈調用上面的方法
  12. for ($i=0;$i<$count;$i++){
  13. //得到檔案的絕對路徑
  14. $abs_dir=dirname(dirname(dirname(dirname(__FILE__))));
  15. //組合路徑
  16. $pa=$abs_dir.'indexRuntime';
  17. $runtime=$abs_dir.'indexRuntime~runtime.php';
  18. if(file_exists($runtime))//判斷 檔案是否存在
  19. {
  20. unlink($runtime);//進行檔案刪除
  21. }
  22. //調用刪除檔案夾下所有檔案的方法
  23. $this->rmFile($pa,$name[$i]);
  24. }
  25. //給出提示資訊
  26. $this->ajaxReturn(1,'清除成功',1);
  27. }else{
  28. $this->display();
  29. }
  30. }
  31. public function rmFile($path,$fileName){//刪除執行的方法
  32. //去除空格
  33. $path = preg_replace('/(/){2,}|{}{1,}/','/',$path);
  34. //得到完整目錄
  35. $path.= $fileName;
  36. //判斷此檔案是否為一個檔案目錄
  37. if(is_dir($path)){
  38. //開啟檔案
  39. if ($dh = opendir($path)){
  40. //遍曆檔案目錄名稱
  41. while (($file = readdir($dh)) != false){
  42. //逐一進行刪除
  43. unlink($path.''.$file);
  44. }
  45. //關閉檔案
  46. closedir($dh);
  47. }
  48. }
  49. }
複製代碼

前台頁面部分代碼:

複製代碼
  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.