diff --git a/controller/ApiController.php b/controller/ApiController.php index 8091286..4b9d446 100644 --- a/controller/ApiController.php +++ b/controller/ApiController.php @@ -215,7 +215,7 @@ Class ApiController extends Controller { } try { - $res = rmdir("{$target}/{$delDir}"); + $res = $this->deleteDirTree( realpath("{$target}/{$delDir}") ); if ($res) { $code = 1; $msg = '目录删除完成'; @@ -397,6 +397,34 @@ Class ApiController extends Controller { return $this->renderJson(compact('code', 'msg', 'err', 'data')); } + protected function deleteDirTree($parentDir) { + if (empty($parentDir)) {return false;} + + $res = true; + + try { + $dir = opendir($parentDir); + + while(false !== ($file = readdir($dir))) { + if ($file != '.' && $file != '..') { + $subpath = "{$parentDir}/{$file}"; + if (is_dir($subpath)) { + $res = $this->deleteDirTree($subpath); + }else { + unlink($subpath); + } + } + } + + closedir($dir); + rmdir($parentDir); + }catch(Excepiton $e) { + $res = false; + } + + return $res; + } + //从runtime/admin/目录里获取管理员当前ip相关的缓存数据 protected function getAdmUserData() { $data = array();