-
- //Get the directory you want to know and the absolute path where the directory is located
- public function cache(){
- ////The front desk uses ajax get to submit, judge it
- if($_POST['type' ]){
- //Get the passed value
- $type=$_POST['type'];
- //Cut the passed value. I used "-" to cut it
- $name=explode(' -', $type);
- //Get the number of cuts to facilitate the following loop
- $count=count($name);
- //Call the above method in a loop
- for ($i=0;$i<$count ;$i++){
- //Get the absolute path of the file
- $abs_dir=dirname(dirname(dirname(dirname(__FILE__)))));
- //Combined path
- $pa=$abs_dir.'indexRuntime';
- $runtime =$abs_dir.'indexRuntime~runtime.php';
- if(file_exists($runtime))//Determine whether the file exists
- {
- unlink($runtime);//Delete the file
- }
- //Call to delete the folder Method to download all files
- $this->rmFile($pa,$name[$i]);
- }
- //Give prompt information
- $this->ajaxReturn(1,'clear successfully',1) ;
- }else{
- $this->display();
- }
- }
- public function rmFile($path,$fileName){//Delete execution method
- //Remove spaces
- $path = preg_replace('/ (/){2,}|{}{1,}/','/',$path);
- //Get the complete directory
- $path.= $fileName;
- //Determine whether this file is a file directory
- if(is_dir($path)){
- //Open the file
- if ($dh = opendir($path)){
- //Traverse the file directory name
- while (($file = readdir($dh)) != false){
- //Delete one by one
- unlink($path.''.$file);
- }
- //Close the file
- closedir($dh);
- }
- }
- }
Copy code
Part of the code on the front page:
-
- $(function(){
- $('#button').click(function(){
- if(confirm("Confirm you want to clear cache?")){
- var $type=$('#type').val ();
- var $mess=$('#mess');
- $.post('__URL__/clear',{type:$type},function(data){
- alert("Cache clearing successful");
- });
- }else{
- return false;
- }
- });
- });
Copy code
|