提交
This commit is contained in:
@@ -21,37 +21,37 @@ class Upload extends Base
|
||||
|
||||
$file = request()->file('file');
|
||||
if (!$file) {
|
||||
return $this->fail('请上传图片');
|
||||
return $this->uploadResponse(0, '请上传图片');
|
||||
}
|
||||
|
||||
$path = $file->getPathname();
|
||||
if (!is_file($path)) {
|
||||
return $this->fail('上传文件读取失败');
|
||||
return $this->uploadResponse(0, '上传文件读取失败');
|
||||
}
|
||||
|
||||
$size = filesize($path);
|
||||
if ($size === false || $size <= 0) {
|
||||
return $this->fail('上传文件为空');
|
||||
return $this->uploadResponse(0, '上传文件为空');
|
||||
}
|
||||
if ($size > 10 * 1024 * 1024) {
|
||||
return $this->fail('图片不能超过10MB');
|
||||
return $this->uploadResponse(0, '图片不能超过10MB');
|
||||
}
|
||||
|
||||
$originalName = (string)($_FILES['file']['name'] ?? 'upload.jpg');
|
||||
$ext = strtolower(pathinfo($originalName, PATHINFO_EXTENSION));
|
||||
$ext = $ext === 'jpeg' ? 'jpg' : $ext;
|
||||
if (!in_array($ext, ['jpg', 'png', 'gif', 'webp', 'bmp'], true)) {
|
||||
return $this->fail('请上传图片文件');
|
||||
return $this->uploadResponse(0, '请上传图片文件');
|
||||
}
|
||||
|
||||
$mime = function_exists('mime_content_type') ? (string)mime_content_type($path) : '';
|
||||
if ($mime !== '' && strpos($mime, 'image/') !== 0) {
|
||||
return $this->fail('请上传图片文件');
|
||||
return $this->uploadResponse(0, '请上传图片文件');
|
||||
}
|
||||
|
||||
$content = file_get_contents($path);
|
||||
if ($content === false || $content === '') {
|
||||
return $this->fail('上传文件读取失败');
|
||||
return $this->uploadResponse(0, '上传文件读取失败');
|
||||
}
|
||||
|
||||
$fileName = date('YmdHis') . uniqid('', true) . '.' . $ext;
|
||||
@@ -72,16 +72,25 @@ class Upload extends Base
|
||||
$client->close();
|
||||
|
||||
if (!$sent) {
|
||||
return $this->fail('上传失败,请重试');
|
||||
return $this->uploadResponse(0, '上传失败,请重试');
|
||||
}
|
||||
|
||||
$url = OSS_URL . $objectKey;
|
||||
return $this->ok([
|
||||
return $this->uploadResponse(1, '上传成功', [
|
||||
'path' => $url,
|
||||
'url' => $url,
|
||||
], '上传成功');
|
||||
]);
|
||||
} catch (\Throwable $e) {
|
||||
return $this->fail('上传失败,请重试');
|
||||
return $this->uploadResponse(0, '上传失败,请重试');
|
||||
}
|
||||
}
|
||||
|
||||
private function uploadResponse(int $code, string $msg, array $data = [])
|
||||
{
|
||||
return json([
|
||||
'code' => $code,
|
||||
'msg' => $msg,
|
||||
'data' => $data,
|
||||
], 200, [], ['json_encode_param' => 0]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -39,7 +39,7 @@ Route::group('miniapi', function () {
|
||||
Route::get('customer-center/orders', 'CustomerCenter/orders');
|
||||
Route::post('customer-center/applicant/save', 'CustomerCenter/saveApplicant');
|
||||
Route::post('customer-center/applicant/remove', 'CustomerCenter/removeApplicant');
|
||||
Route::post('customer-center/applicant', 'CustomerCenter/applicant');
|
||||
Route::post('customer-center/applicant', 'CustomerCenter/applicant')->completeMatch();
|
||||
|
||||
Route::get('ocr/signature', 'Ocr/signature');
|
||||
Route::post('upload/image', 'Upload/image');
|
||||
|
||||
Reference in New Issue
Block a user