From c3d622545a070fd12a5c3036a9b78814ddf48126 Mon Sep 17 00:00:00 2001 From: liapples Date: Wed, 28 Jul 2021 18:45:51 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E6=96=87=E4=BB=B6=E4=B8=8A?= =?UTF-8?q?=E4=BC=A0=E6=8E=A7=E5=88=B6=E5=99=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Http/Controllers/Api/UploadController.php | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 app/Http/Controllers/Api/UploadController.php diff --git a/app/Http/Controllers/Api/UploadController.php b/app/Http/Controllers/Api/UploadController.php new file mode 100644 index 0000000..54e3872 --- /dev/null +++ b/app/Http/Controllers/Api/UploadController.php @@ -0,0 +1,33 @@ +file('image'); + if (!$image->isValid()) { + return $this->error('未获取到任何文件'); + } + + $mime = $image->getMimeType(); + if (!in_array($mime, ['image/jpeg', 'image/png', 'image/gif', 'image/pjpeg'])) { + return $this->error('所上传图片格式错误'); + } + + $path = $request->image->store('images', 'uploads'); + return $this->success(['path' => env('APP_URL') . $this->save_path . $path]); + } +}