Thinkphp file processing class Dir. class. php Usage analysis, _ PHP Tutorial

Source: Internet
Author: User
Tags delete cache
Thinkphp file processing class Dir. class. php Usage analysis ,. The usage analysis of thinkphp file processing class Dir. class. php. This article analyzes the usage of thinkphp file processing class Dir. class. php. Share it with you for your reference. The specific analysis is as follows: Analysis on the usage of thinkphp file processing class Dir. class. php,

This article analyzes the usage of thinkphp file processing class Dir. class. php. Share it with you for your reference. The specific analysis is as follows:

In my WBlog, a cache cleanup worker can delete cache files generated when the program is running. all these files are stored in the Runtime folder of the project, at that time, when I used a function customized by the Project function library to delete the cached files, I could only delete the entire Runtime. it was too rough. I think it is necessary to perform a further deletion, in fact, the thinkphp extension class library has a good file processing class Dir. class. php, Dir. class. php class, not all thinkphp versions are available. if the version you downloaded does not exist, you can find it from other versions. now let's talk about Dir. class. php applications.

Dir. class. php is a file processing class. you can use it:

1. get the file information under the Directory

2. delete a directory or file

As I want to improve the WBlog Cache clearing function, I only write the above 2nd functions. As for the 1st functions, I will write the template text modification function again, the following is a del () method defined by the controller that is clearing the cache:

The code is as follows:

Public function del (){
$ Type = trim ($ _ GET ['type']);
If (emptyempty ($ type) $ this-> error ('select the cache type! ');

Switch ($ type ){
Case 1: // clear all
$ Path = WEB_PATH. 'runtime ';
Break;
Case 2: // file cache Directory
$ Path = WEB_PATH. 'runtime/Temp ';
Break;
Case 3: // Data Directory
$ Path = WEB_PATH. 'runtime/Data/_ fields ';
Break;
Case 4: // template file cache
$ Path = WEB_PATH. 'runtime/cache ';
Break;
Case 5: // clear all background caches
$ Path = APP_PATH. 'runtime ';
Break;
Case 6: // background file cache Directory
$ Path = APP_PATH. 'runtime/Temp ';
Break;
Case 7: // background data directory
$ Path = APP_PATH. 'runtime/Data/_ fields ';
Break;
Case 8: // template file cache
$ Path = APP_PATH. 'runtime/cache ';
Break;
}

Import ("@. ORG. Dir"); // load the Dir. class. php class (I put it in the background Project)

If (! Dir: isEmpty ($ path) {// call isEmpty () of Dir. class. php statically ()
Dir: del ($ path );

$ This-> success ();
} Else {
$ This-> error ('cleared! ');
}
}


Note:

Import ("@. ORG. Dir") -- load the Dir. class. php class (I put it in the background Project)

Dir: isEmpty ($ path) -- call the isEmpty () of Dir. class. php statically ()

Dir: del ($ path); -- call the del () method of Dir. class. php statically.

I used static call methods when I used classes, which saves the trouble of instantiation.

I hope this article will help you design PHP programs based on the ThinkPHP framework.

Example: This article analyzes the usage of thinkphp file processing class Dir. class. php. Share it with you for your reference. The specific analysis is as follows...

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.