thinkphp one-click clear cache method code

WBOY
Release: 2016-07-25 08:52:18
Original
1131 people have browsed it
  1. //Get the directory you want to know and the absolute path where the directory is located
  2. public function cache(){
  3. ////The front desk uses ajax get to submit, judge it
  4. if($_POST['type' ]){
  5. //Get the passed value
  6. $type=$_POST['type'];
  7. //Cut the passed value. I used "-" to cut it
  8. $name=explode(' -', $type);
  9. //Get the number of cuts to facilitate the following loop
  10. $count=count($name);
  11. //Call the above method in a loop
  12. for ($i=0;$i<$count ;$i++){
  13. //Get the absolute path of the file
  14. $abs_dir=dirname(dirname(dirname(dirname(__FILE__)))));
  15. //Combined path
  16. $pa=$abs_dir.'indexRuntime';
  17. $runtime =$abs_dir.'indexRuntime~runtime.php';
  18. if(file_exists($runtime))//Determine whether the file exists
  19. {
  20. unlink($runtime);//Delete the file
  21. }
  22. //Call to delete the folder Method to download all files
  23. $this->rmFile($pa,$name[$i]);
  24. }
  25. //Give prompt information
  26. $this->ajaxReturn(1,'clear successfully',1) ;
  27. }else{
  28. $this->display();
  29. }
  30. }
  31. public function rmFile($path,$fileName){//Delete execution method
  32. //Remove spaces
  33. $path = preg_replace('/ (/){2,}|{}{1,}/','/',$path);
  34. //Get the complete directory
  35. $path.= $fileName;
  36. //Determine whether this file is a file directory
  37. if(is_dir($path)){
  38. //Open the file
  39. if ($dh = opendir($path)){
  40. //Traverse the file directory name
  41. while (($file = readdir($dh)) != false){
  42. //Delete one by one
  43. unlink($path.''.$file);
  44. }
  45. //Close the file
  46. closedir($dh);
  47. }
  48. }
  49. }
Copy code

Part of the code on the front page:

Copy code


source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template