Common.php
// 删除目录及文件,传入目录 function delFileByDir($dir){ $dh = opendir($dir); while($file = readdir($dh)){ if($file != "." && $file != ".."){ $fullpath = $dir . "/" .$file; if(is_dir($fullpath)){ delFileByDir($fullpath); }else{ unlink($fullpath); } } } closedir($dh); }
Config.php 控制器下
// 清空runtime下缓存文件 public function del_cache() { // 删除runtime 目录 $path = root_pth().'runtime'; delFileByDir($path); return alert('清除缓存成功','index/index',6); }