Thinkphp a key to clear the cache method code

Source: Internet
Author: User
  1. Get the absolute path of directories and directories to be clear
  2. Public Function cache () {
  3. The foreground is submitted using Ajax get method, judging by
  4. if ($_post[' type ']) {
  5. Get the value passed over
  6. $type =$_post[' type '];
  7. To cut the passed value, I cut it with "-"
  8. $name =explode ('-', $type);
  9. The number of strips to be cut to facilitate the loop below
  10. $count =count ($name);
  11. Loop calls the above method
  12. for ($i =0; $i < $count; $i + +) {
  13. Get the absolute path to the file
  14. $abs _dir=dirname (DirName (DirName (dirname (__file__)));
  15. Combining paths
  16. $pa = $abs _dir. ' Indexruntime ';
  17. $runtime = $abs _dir. ' indexruntime~runtime.php ';
  18. if (file_exists ($runtime))//Determine if the file exists
  19. {
  20. Unlink ($runtime);//File deletion
  21. }
  22. method to invoke all files under Delete folder
  23. $this->rmfile ($pa, $name [$i]);
  24. }
  25. Give a hint
  26. $this->ajaxreturn (1, ' clear Success ', 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 full Catalog
  35. $path. = $fileName;
  36. Determine if this file is a file directory
  37. if (Is_dir ($path)) {
  38. Open File
  39. if ($dh = Opendir ($path)) {
  40. Traverse file Directory Name
  41. while (($file = Readdir ($DH)) = = False) {
  42. Delete them individually
  43. Unlink ($path. $file);
  44. }
  45. Close File
  46. Closedir ($DH);
  47. }
  48. }
  49. }
Copy Code

Front page Section code:

Copy Code
  • Related Article

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    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.