chore(src): 使用绝对路径来判断权限

This commit is contained in:
2025-12-02 17:18:00 +08:00
parent c24271c075
commit 4346bfebb7

View File

@@ -890,17 +890,22 @@ class Upload extends BaseModel
*/
public function checkPath($path)
{
$absolute_path = realpath($path);
$current_user = get_current_user();
$current_user = $current_user ? $current_user : 'unknown';
$current_work_dir = getcwd();
$current_work_dir = $current_work_dir ? $current_work_dir : 'unknown';
// 如果$path包含工作目录需要转换为绝对路径
$absolute_path = $path;
if (strpos($path, $current_work_dir) !== false) {
$absolute_path = $current_work_dir . "/" . $path;
}
try {
if (file_exists($absolute_path) || mkdir($absolute_path, 0755, true)) {
return $this->success();
}
} catch (\Exception $e) {
$current_user = get_current_user();
$current_user = $current_user ? $current_user : 'unknown';
$current_work_dir = getcwd();
$current_work_dir = $current_work_dir ? $current_work_dir : 'unknown';
return $this->error('', "上传目录 {$absolute_path} 创建失败,请检测权限:用户{$current_user},当前工作目录{$current_work_dir}" . $e->getMessage());
}
}