The usage Analysis _php instance of thinkphp file processing class Dir.class.php

Source: Internet
Author: User

The use of thinkphp file processing class Dir.class.php is analyzed in this paper. Share to everyone for your reference. The specific analysis is as follows:

In my wblog, there is a cleanup cache worker, the so-called clear cache is the deletion of the program runtime generated cache files, all of these files are in the project's Runtime folder, when the program to clear the cache using the Project function library customized a function to delete the cached files, Can only delete the runtime, too rough, I think it is necessary to make a subdivision delete, in fact, thinkphp Extended class library has a good file processing class dir.class.php,dir.class.php class, not every thinkphp version has, If you have downloaded a version that is not available, you can look for it from another version, now for the Dir.class.php application.

Dir.class.php is a file processing class that can be used to:

1, access to the directory under the file information

2. Delete directory or file

Because I want to perfect the Wblog cache cleanup function, here I only wrote the 2nd function above, as for the 1th function I will do template text to modify the function to write, the following is I clear the cache of the controller definition of a del () method:

Copy Code code as follows:
Public Function del () {
$type =trim ($_get[' type '));
if (Emptyempty ($type)) $this->error (' Please select cache type! ');

Switch ($type) {
Case 1://all clear.
$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://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 Dir.class.php IsEmpty ()
Dir::d El ($path);

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

Description

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

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

Dir::d El ($path);--Static calls the Dir.class.php del () method.

I used the static invocation method when I used the class, which eliminates the hassle of instantiating it.

I hope this article will help you with the PHP program design based on thinkphp framework.

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.