From afd1b88fdc85359739d58ff8fee892a36213d017 Mon Sep 17 00:00:00 2001 From: sugar1569 Date: Thu, 18 Apr 2019 11:49:49 +0800 Subject: [PATCH] =?UTF-8?q?=E5=90=8E=E5=8F=B0=E6=B8=85=E9=99=A4=E7=BC=93?= =?UTF-8?q?=E5=AD=98bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- application/admin/controller/system/Clear.php | 30 ++++++++++++------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/application/admin/controller/system/Clear.php b/application/admin/controller/system/Clear.php index b90fc4fc..73a0281a 100644 --- a/application/admin/controller/system/Clear.php +++ b/application/admin/controller/system/Clear.php @@ -25,32 +25,42 @@ class Clear extends AuthController * 刷新数据缓存 */ public function refresh_cache(){ - `php think optimize:schema`; - `php think optimize:autoload`; - `php think optimize:route`; - `php think optimize:config`; + if(function_exists('shell_exec')){ + `php think optimize:schema`; + `php think optimize:autoload`; + `php think optimize:route`; + `php think optimize:config`; + }else if(function_exists('exec')){ + exec('php think optimize:schema'); + exec('php think optimize:autoload'); + exec('php think optimize:route'); + exec('php think optimize:config'); + }else{ + return Json::successful('请开启shell_exec或者exec函数!'); + } return Json::successful('数据缓存刷新成功!'); } - /** * 删除缓存 */ public function delete_cache(){ - Cache::clear(); - array_map('unlink', glob(TEMP_PATH . '/*.php')); + $this->delDirAndFile(TEMP_PATH); + $this->delDirAndFile(CACHE_PATH); return Json::successful('清除缓存成功!'); } - /** * 删除日志 */ public function delete_log(){ - array_map('unlink', glob(LOG_PATH . '/*.log')); $this->delDirAndFile(LOG_PATH); return Json::successful('清除日志成功!'); } - function delDirAndFile($dirName,$subdir=true){ + /** 递归删除文件 + * @param $dirName + * @param bool $subdir + */ + function delDirAndFile($dirName,$subdir = true){ if ($handle = opendir("$dirName")){ while(false !== ($item = readdir($handle))){ if($item != "." && $item != ".."){