Usage analysis of thinkphp file processing class Dir.class.php, _PHP tutorial

WBOY
Release: 2016-07-13 10:12:13
Original
1018 people have browsed it

Usage analysis of thinkphp file processing class Dir.class.php,

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:

Copy code The code is as follows:
public function del(){   
$type=trim($_GET['type']);
If(emptyempty($type)) $this->error('Please 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:// Backend file cache directory
                                                                                                                                                                                                                                                                                                                           break;                                      case 7:// Backend data directory
                                                                                                                                                                                                                                                                                                                              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)){//Static call isEmpty() of Dir.class.php
Dir::del($path);
                                                                        $this->success();
}else{  
$this->error('Cleared!');
}  
}

Description:

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.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/923898.htmlTechArticleUsage analysis of thinkphp file processing class Dir.class.php. This article analyzes the thinkphp file processing class Dir.class with examples. .php usage. Share it with everyone for your reference. The specific analysis is as follows: In...
Related labels:
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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!