Thinkphp one-click Cache clearing method code
- // Obtain the absolute path of the desired directory and Directory
- Public function cache (){
- /// The front-end submits the request in ajax get mode.
- If ($ _ POST ['type']) {
- // Obtain the passed value
- $ Type = $ _ POST ['type'];
- // Cut the passed value. I used "-" to cut the value.
- $ 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. 'indexruntime ';
- $ Runtime = $ abs_dir. 'indexruntime ~ Runtime. php ';
- If (file_exists ($ runtime) // checks whether the object exists.
- {
- Unlink ($ runtime); // delete a file
- }
- // 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 ();
- }
- }
- Public function rmFile ($ path, $ fileName) {// delete the execution method
- // 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 );
- }
- }
- }
Code of the front-end page:
|