fix:图片上传接口修改
This commit is contained in:
parent
06b8c43b57
commit
c4b218b002
@ -24,11 +24,20 @@ class Common extends BaseController
|
|||||||
|
|
||||||
$upload = new UploadFile('uploads', 'file');
|
$upload = new UploadFile('uploads', 'file');
|
||||||
$path = $upload->putFile($dirName . 'Img');
|
$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 [
|
return [
|
||||||
'code' => 0,
|
'code' => 0,
|
||||||
'data' => [
|
'data' => [
|
||||||
"name" => $path,
|
"name" => $path,
|
||||||
"url" => "/uploads/" . $path,
|
"url" => $url,
|
||||||
],
|
],
|
||||||
'msg' => '上传成功!'
|
'msg' => '上传成功!'
|
||||||
];
|
];
|
||||||
|
Loading…
Reference in New Issue
Block a user