From 05c1b08e95ea8f95c7798c7b2920ddc6da799a2b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=8A=80=E6=9C=AF=E8=80=81=E8=83=A1?= <1094551889@qq.com> Date: Fri, 20 Dec 2024 11:16:57 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=9B=BE=E7=89=87=E4=B8=8A?= =?UTF-8?q?=E4=BC=A0=E6=96=87=E4=BB=B6=E6=BC=8F=E6=B4=9E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controller/api/PayManageController.php | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/app/controller/api/PayManageController.php b/app/controller/api/PayManageController.php index 7a533fe..b78ab9e 100644 --- a/app/controller/api/PayManageController.php +++ b/app/controller/api/PayManageController.php @@ -125,14 +125,27 @@ class PayManageController extends BaseController public function uploadQrcode() { $img = $this->request->file('codeimg'); + if (!$img) { + return json(backMsg(1, '请选择要上传的文件')); + } + // 验证文件类型 + $allowedTypes = ['image/png', 'image/jpeg', 'image/gif']; + $fileMimeType = $img->getMime(); + if (!in_array($fileMimeType, $allowedTypes)) { + return json(backMsg(1, '只允许上传PNG、JPEG或GIF格式的图片')); + } + // 生成唯一文件名 + $filename = 'img_' . time() . '_' . uniqid() . '.' . $img->getOriginalExtension(); + // 设置文件保存路径 $path = public_path() . '/files/qrcode/'; if (!is_dir($path)) { - mkdir($path, 0777, true); + mkdir($path, 0755, true); } - $info = $img->move($path, 'img' . time() . '.' . $img->getOriginalExtension()); + // 移动文件到指定目录 + $info = $img->move($path, $filename); if ($info) { - $imgpath = '/files/qrcode/'; - return json(backMsg(0, '上传成功', ['imgpath' => $imgpath . $info->getFilename()])); + $imgpath = '/files/qrcode/' . $filename; + return json(backMsg(0, '上传成功', ['imgpath' => $imgpath])); } else { return json(backMsg(1, '上传失败')); }