diff --git a/controller/ApiController.php b/controller/ApiController.php index d18a221..9e501f5 100644 --- a/controller/ApiController.php +++ b/controller/ApiController.php @@ -53,7 +53,7 @@ Class ApiController extends Controller { $realpath = preg_replace('/\/$/', '', $realpath); $arr = explode('/', $realpath); - if (count($arr) < 2) {return '/';} + if (count($arr) < 2 || empty($arr[0])) {return '/';} array_pop($arr); return implode('/', $arr); @@ -61,7 +61,7 @@ Class ApiController extends Controller { //判断父目录是否合法 protected function isParentDirectoryValid($parentDir) { - if (empty($parentDir) || strpos($parentDir, '../') !== false) { + if (empty($parentDir) || strpos($parentDir, '..') !== false) { return false; }else if ($realpath == '/') { return true; @@ -286,7 +286,7 @@ Class ApiController extends Controller { return $this->renderJson(compact('code', 'msg', 'err', 'data'), $this->httpStatus['notAllowed']); } - $fromFile = str_replace("{$fromParent}/", '', $fromDir); + $fromFile = $this->basename($fromDir); $toDir = preg_match('/\/$/', $toDir) ? "{$toDir}{$fromFile}" : "{$toDir}/{$fromFile}"; }