fix:图片上传接口修改

This commit is contained in:
xjh 2023-05-03 20:34:13 +08:00
parent 06b8c43b57
commit c4b218b002

View File

@ -24,11 +24,20 @@ class Common extends BaseController
$upload = new UploadFile('uploads', 'file');
$path = $upload->putFile($dirName . 'Img');
$url = "/uploads/" . $path;
//图片大小>500k压缩图片质量
$absolute_path = public_path() . $url;
if (ceil(filesize($absolute_path) / 1000) > 500) {
$image = \think\Image::open($absolute_path);
$image->save($absolute_path, null, 80);
}
return [
'code' => 0,
'data' => [
"name" => $path,
"url" => "/uploads/" . $path,
"url" => $url,
],
'msg' => '上传成功!'
];