// +---------------------------------------------------------------------- declare (strict_types = 1); namespace app\common\library\storage; class FileValidate extends \think\Validate { // 验证规则 protected $rule = [ // 文件大小: 2MB = (1024 * 1024 * 2) = 2097152 字节 // 文件扩展名: jpg,jpeg,png,bmp,gif 'image' => 'filesize:2097152|fileExt:jpg,jpeg,png,bmp,gif', 'annex' => 'filesize:2097152|fileExt:xls', ]; // 错误提示信息 protected $message = [ 'image.filesize' => '文件大小不能超出2MB', 'image.fileExt' => '文件扩展名有误', 'annex.filesize' => '文件大小不能超出2MB', 'annex.fileExt' => '不支持的文件格式', ]; // 验证场景 protected $scene = [ 'image' => ['image'], 'annex' => ['annex'], ]; }