This commit is contained in:
toom1996
2025-07-02 16:44:04 +08:00
parent f060934b86
commit 716e20675e
4 changed files with 24 additions and 9 deletions

View File

@ -69,10 +69,10 @@ class UploadController extends AbstractController
}
// 校验类型
$allowedTypes = ['image/jpeg', 'image/png', 'image/gif', 'image/webp'];
if (!in_array($file->getClientMediaType(), $allowedTypes)) {
return $this->response->json(['code' => 415, 'msg' => '不支持的图片格式']);
}
// $allowedTypes = ['image/jpeg', 'image/png', 'image/gif', 'image/webp'];
// if (!in_array($file->getClientMediaType(), $allowedTypes)) {
// return $this->response->json(['code' => 415, 'msg' => '不支持的图片格式']);
// }
// 限制大小 (例如 5MB)
$maxSize = 5 * 1024 * 1024;
@ -82,7 +82,7 @@ class UploadController extends AbstractController
// 保存路径
$filename = uniqid() . '.' . pathinfo($file->getClientFilename(), PATHINFO_EXTENSION);
$targetPath = BASE_PATH . '/uploads/' . $filename;
$targetPath = BASE_PATH . '/public/uploads/' . $filename;
// 确保目录存在
if (!is_dir(dirname($targetPath))) {
@ -98,7 +98,7 @@ class UploadController extends AbstractController
return $this->response->json([
'errno' => 0,
'msg' => '上传成功!!',
'msg' => '上传成功!!~',
'data' => [
'url' => Config::getDomain() . $url,
]