Home >Backend Development >PHP Tutorial >Usage analysis of thinkphp file processing class Dir.class.php, _PHP tutorial
This article analyzes the usage of thinkphp file processing class Dir.class.php with examples. Share it with everyone for your reference. The specific analysis is as follows:
In my WBlog, there is a clear cache function. The so-called clear cache is to delete the cache files generated when the program is running. All these files are stored in the runtime folder of the project. When I was doing this clear cache program Using a function customized by the project function library to delete cache files can only delete the Runtime as a whole, which is too rough. I think it is necessary to do a subdivided deletion. In fact, the thinkphp extension class library has a good file processing class Dir.class .php, Dir.class.php is not available in every thinkphp version. If the version you downloaded does not have it, you can find it from other versions. Now let’s talk about the application of Dir.class.php.
Dir.class.php is a file processing class, you can use it:
1. Obtain the file information under the directory
2. Delete directories or files
Since I want to improve the WBlog cache clearing function, I only wrote the second function above. As for the first function, I will write it when I modify the template text. The following is the controller I use to clear the cache. A del() method defined:
import("@.ORG.Dir") --Load the Dir.class.php class (I put it in the background project)
Dir::isEmpty($path)--statically calling isEmpty() of Dir.class.php
Dir::del($path);--statically call the del() method of Dir.class.php.
When using the class above, I used static calling methods, which saves the trouble of instantiation.
I hope this article will be helpful to everyone’s PHP programming based on the ThinkPHP framework.