添加上传大小限制20M

This commit is contained in:
Dai 2025-05-14 19:28:44 +08:00
parent 9a4f207d37
commit b163364831
2 changed files with 16 additions and 2 deletions

View File

@ -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') . '/';

View File

@ -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
];