chore(src): 检查路径的权限

This commit is contained in:
2025-12-02 17:15:02 +08:00
parent 526982c431
commit c24271c075

View File

@@ -885,13 +885,15 @@ class Upload extends BaseModel
/** /**
* 验证目录是否可写 * 验证目录是否可写
* @param unknown $path * @param string $path
* @return boolean * @return boolean
*/ */
public function checkPath($path) public function checkPath($path)
{ {
$absolute_path = realpath($path);
try { try {
if (file_exists($path) || mkdir($path, 0755, true)) {
if (file_exists($absolute_path) || mkdir($absolute_path, 0755, true)) {
return $this->success(); return $this->success();
} }
} catch (\Exception $e) { } catch (\Exception $e) {
@@ -899,7 +901,7 @@ class Upload extends BaseModel
$current_user = $current_user ? $current_user : 'unknown'; $current_user = $current_user ? $current_user : 'unknown';
$current_work_dir = getcwd(); $current_work_dir = getcwd();
$current_work_dir = $current_work_dir ? $current_work_dir : 'unknown'; $current_work_dir = $current_work_dir ? $current_work_dir : 'unknown';
return $this->error('', "上传目录 {$path} 创建失败,请检测权限:用户{$current_user},当前工作目录{$current_work_dir}" . $e->getMessage()); return $this->error('', "上传目录 {$absolute_path} 创建失败,请检测权限:用户{$current_user},当前工作目录{$current_work_dir}" . $e->getMessage());
} }
} }