thinkphp file processing class Dir.class.php usage analysis, _php tutorial

Source: Internet
Author: User

The usage analysis of thinkphp file processing class Dir.class.php,


This paper analyzes the usage of thinkphp file processing class Dir.class.php. Share to everyone for your reference. The specific analysis is as follows:

In my wblog, there is a clear cache work, so-called clear cache is the deletion of the program runtime generated cache files, all of these files exist in the runtime folder of the project, when the program to clear the cache using the Project function library to customize a function to delete the cache file, Can only delete the runtime, too rough, I think it is necessary to make a subdivision delete, in fact, thinkphp Extension class library has a good file processing class dir.class.php,dir.class.php class, not every thinkphp version has, If the version you downloaded is not available, you can find it from other versions, now for the Dir.class.php application.

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

1, obtain the file information under the directory

2. Delete a directory or file

Since I want to improve the Wblog cache cleanup function, here I only wrote the 2nd function above, as for the 1th function I will do the template text modification function when again write, below is I clear the cache controller definition of a del () method:
Copy CodeThe 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://All empty
$path = Web_path. ' Runtime ';
Break
Case 2://File Cache directory
$path = Web_path. ' Runtime/temp ';
Break
Case 3://Data Catalog
$path = Web_path. ' Runtime/data/_fields ';
Break
Case 4://Template File cache
$path = Web_path. ' Runtime/cache ';
Break
Case 5://empty all background cache
$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 Dir.class.php class (I put it in the background project)

if (! Dir::isempty ($path)) {//static call to Dir.class.php IsEmpty ()
Dir::d El ($path);

$this->success ();
}else{
$this->error (' Emptied! ');
}
}
Description

Import ("@.org.dir")--Load Dir.class.php class (I put in the background project)

Dir::isempty ($path)--Static call to Dir.class.php IsEmpty ()

Dir::d El ($path);--Static call to Dir.class.php's Del () method.

I used the static calling method when I used the class above, which eliminates the hassle of instantiation.

It is hoped that this article is helpful to the PHP program design based on thinkphp framework.

http://www.bkjia.com/PHPjc/923898.html www.bkjia.com true http://www.bkjia.com/PHPjc/923898.html techarticle The usage analysis of thinkphp file processing class Dir.class.php, this paper analyzes the usage of thinkphp file processing class Dir.class.php. Share to everyone for your reference. The specific analysis is as follows: in ...

  • 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.