后台控制器: <?php namespace Home\Controller; use Think\Controller; class HuancuController extends Controller{ private function _deleteDir($R){ $handle = opendir($R); while(($item = readdir($handle)) !== false){ if($item != '.' and $item != '..'){ if(is_dir($R.'/'.$item)){ $this->_deleteDir($R.'/'.$item); }else{ if(!unlink($R.'/'.$item)) die('error!'); } } } closedir( $handle ); return rmdir($R); } public function clearRuntime(){ if($_POST['user']==1){ if($this->_deleteDir("./Runtime/")){ $this->ajaxReturn(1); } } } } 前台代码 ajax请求: <script type="text/javascript"> function zp(){ $.ajax({ type: "POST", url:"{:U('Huancu/clearRuntime')}", data:{user:1}, success:function(r){ if(r==1){ alert('清除成功!'); } } }) } </script>
评论(0)