控制器
<?php namespace Admin\Controller; use Think\Controller; class ClearController extends Controller { public function clearcache(){ /*通过删除runtime 文件夹*/ $rtim=del_dir(APP_PATH.'Runtime'); if($rtim){ $this->success('清除成功'); echo '<script language="javascript">'; echo 'parent.location.reload();'; echo '</script>'; }else{ $this->error('清除失败'); } } }
公共函数
/*删除文件夹*/ function del_dir($dir) { $dh=opendir($dir); while ($file=readdir($dh)) { if($file!="." && $file!="..") { $fullpath=$dir."/".$file; if(!is_dir($fullpath)) { @unlink($fullpath); } else { del_dir($fullpath); } } } closedir($dh); if(rmdir($dir)) { return true; } else { return false; } }
视图
<a href="__MODULE__/Clear/clearcache" target="right">清除缓冲</a>