From b163364831f44da6855b89d3534b3bcc299e19f1 Mon Sep 17 00:00:00 2001 From: Dai Date: Wed, 14 May 2025 19:28:44 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E4=B8=8A=E4=BC=A0=E5=A4=A7?= =?UTF-8?q?=E5=B0=8F=E9=99=90=E5=88=B620M?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/common/service/UploadService.php | 16 +++++++++++++++- config/server.php | 2 +- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/app/common/service/UploadService.php b/app/common/service/UploadService.php index 71a29d7..e0197a6 100644 --- a/app/common/service/UploadService.php +++ b/app/common/service/UploadService.php @@ -24,6 +24,13 @@ class UploadService } $fileSize = $file->getSize(); + if ($fileSize > 20 * 1024 * 1024){ + return [ + 'code' => ResponseCode::FAIL, + 'msg' => '图片超出20M', + ]; + } + $uploadDir = '/files/' . $type . '/' . date('Ym') . '/'; $filename = date('YmdHis') . rand(999, 99999); $uploadPath = $uploadDir . $filename . '.' . $ext; @@ -67,12 +74,19 @@ class UploadService if ($file && $file->isValid()) { $ext = $file->getUploadExtension(); - if (in_array($ext, ['pdf', 'doc', 'docx', 'xlsx', 'xls', 'csv', 'pptx', 'ppt', 'zip', 'jpg', 'jpeg', 'png', 'gif', 'bmp', 'JPG', 'JPEG', 'PBG', 'txt'])) { + if (in_array($ext, ['pdf', 'doc', 'docx', 'xlsx', 'xls', 'csv', 'pptx', 'ppt', 'zip', 'jpg', 'jpeg', 'png', 'gif', 'bmp', 'JPG', 'JPEG', 'PBG', 'txt', 'zip', 'rar', '7z', 'tgz'])) { $type = 'files'; } else { $type = 'other'; } $fileSize = $file->getSize(); + + if ($fileSize > 20 * 1024 * 1024){ + return [ + 'code' => ResponseCode::FAIL, + 'msg' => '文件超出20M', + ]; + } $origin_name = $file->getUploadName(); $uploadDir = '/files/' . $type . '/' . date('Ym') . '/'; diff --git a/config/server.php b/config/server.php index 5829aa2..cb0577b 100644 --- a/config/server.php +++ b/config/server.php @@ -27,5 +27,5 @@ return [ 'status_file' => runtime_path() . '/webman.status', 'stdout_file' => runtime_path() . '/logs/stdout.log', 'log_file' => runtime_path() . '/logs/workerman.log', - 'max_package_size' => 10 * 1024 * 1024 + 'max_package_size' => 20 * 1024 * 1024 ];