<?php
declare (strict_types = 1);
namespace app\index\validate;
use think\Validate;
class Upload extends Validate
{
/**
* 定义验证规则
* 格式:'字段名' => ['规则1','规则2'...]
*
* @var array
*/
protected $rule = [
'image' => 'fileExt:jpg,png|fileSize:204800|fileMime:image/jpeg,image/png', // 文件扩展名限制为jpg, png;文件大小限制为200K;文件MIME类型限制为image/jpeg, image/png
];
/**
* 定义错误信息
* 格式:'字段名.规则名' => '错误信息'
*
* @var array
*/
protected $message = [
'image.fileExt' => '图片格式必须为jpg或png',
'image.fileSize' => '图片大小不能超过200K',
];
}
在index应用下,创建了验证器;
<?php
declare (strict_types = 1);
namespace app\index\controller;
use think\Request;
use app\ind