ThinkPHP clears cache/deletes all files in the folder

Source: Internet
Author: User
ThinkPHP clears the cache and deletes all files in the folder. Today, the ThinkPHP clears the cache function. I opened a simple method on the Internet, but it is a built-in class of ThinkPHP, I haven't found this class for a long time, so I am so angry. & nbsp; so I used php to delete all the files in the folder to clear the slow cache function. I don't need to talk about sticking to the code: * This method is a public method used to delete all files in a folder & nb ThinkPHP clear cache/delete all files in the folder

Today I made a ThinkPHP Cache clearing function. I opened a simple method on the Internet, but it is a built-in class of ThinkPHP. I haven't found this class for a long time, as soon as I got angry, I used php to delete all files in the folder to clear the slow cache function. I didn't talk much about sticking the code to it:

/* This is a public method used to delete all objects in a folder.
* $ Path indicates the file path.
* $ FileName folder name
**/
Public function rmFile ($ path, $ fileName ){
// Remove spaces
$ Path = preg_replace ('/(\/) {2, }|{\\\}{ 1,}/', '/', $ path );
// Obtain The Complete Directory
$ Path. = $ fileName;
// Determine whether the file is a file directory
If (is_dir ($ path )){
// Open the file
If ($ dh = opendir ($ path )){
// Retrieve the file directory name
While ($ file = readdir ($ dh ))! = False ){
// Delete one by one
Unlink ($ path. '\'. $ file );
}
// Close the file
Closedir ($ dh );
}
}
}

// One-to-one deletion of cache
Public function cache (){

// The front-end submits the request using ajax get. here we will first judge
If ($ _ GET ['type']) {

// Obtain the submitted value (that is, the name of the folder to be deleted)

$ Type = $ _ GET ['type'];

// Obtain the absolute path of the object

$ Abs_dir = dirname (_ FILE __))));

// Combine with the files in the folder to be deleted
$ Pa = $ abs_dir. '\ Admin \ Runtime \\';

// Call the method written above

$ This-> rmFile ($ pa, $ type );

// Return the prompt message
$ This-> ajaxReturn (1, 'cleared successfully', 1 );
} Else {
$ This-> display ();
}
}

// Clear all caches with one click
Public function allrun (){

/// The front-end submits the request in ajax get mode. here we will first judge
If ($ _ GET ['type']) {

// Obtain the passed value
$ Type = $ _ GET ['type'];

// Cut the passed value. I have "-" cut
$ Name = explode ('-', $ type );

// Obtain the number of slices to facilitate the following cycle

$ Count = count ($ name );

// Call the above method cyclically

For ($ I = 0; $ I <$ count; $ I ++ ){

// Obtain the absolute path of the object

$ Abs_dir = dirname (_ FILE __))));

// Combined path
$ Pa = $ abs_dir. '\ Admin \ Runtime \\';

// Call the method to delete all objects in a folder
$ This-> rmFile ($ pa, $ name [$ I]);
}

// Provides prompt information

$ This-> ajaxReturn (1, 'cleared successfully', 1 );
} Else {
$ This-> display ();
}
}

The front-end page is very simple. here we will provide important code.

Html file

// This is submitted in ajax get mode.

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.