82 lines
2.9 KiB
PHP
82 lines
2.9 KiB
PHP
<?php
|
|
|
|
namespace app\common\validate;
|
|
|
|
use think\Validate;
|
|
|
|
class UploadedFilesValidate extends Validate
|
|
{
|
|
/**
|
|
* 验证规则
|
|
*/
|
|
protected $rule = [
|
|
'file_name' => 'require|max:255',
|
|
'file_path' => 'require|max:500',
|
|
'file_size' => 'require|integer|gt:0',
|
|
'file_type' => 'require|max:100',
|
|
'category' => 'require|max:50',
|
|
'original_name' => 'max:255',
|
|
'extension' => 'max:20',
|
|
'partition' => 'max:50',
|
|
'upload_ip' => 'ip',
|
|
'user_agent' => 'max:500',
|
|
];
|
|
|
|
/**
|
|
* 验证消息
|
|
*/
|
|
protected $message = [
|
|
'file_name.require' => '文件名不能为空',
|
|
'file_name.max' => '文件名长度不能超过255个字符',
|
|
'file_path.require' => '文件路径不能为空',
|
|
'file_path.max' => '文件路径长度不能超过500个字符',
|
|
'file_size.require' => '文件大小不能为空',
|
|
'file_size.integer' => '文件大小必须是整数',
|
|
'file_size.gt' => '文件大小必须大于0',
|
|
'file_type.require' => '文件类型不能为空',
|
|
'file_type.max' => '文件类型长度不能超过100个字符',
|
|
'category.require' => '文件分类不能为空',
|
|
'category.max' => '文件分类长度不能超过50个字符',
|
|
'original_name.max' => '原始文件名长度不能超过255个字符',
|
|
'extension.max' => '文件扩展名长度不能超过20个字符',
|
|
'partition.max' => '分区名称长度不能超过50个字符',
|
|
'upload_ip.ip' => '上传IP格式不正确',
|
|
'user_agent.max' => '用户代理长度不能超过500个字符',
|
|
];
|
|
|
|
/**
|
|
* 验证场景
|
|
*/
|
|
protected $scene = [
|
|
'create' => ['file_name', 'file_path', 'file_size', 'file_type', 'category'],
|
|
'update' => ['file_name', 'file_path', 'file_size', 'file_type', 'category', 'original_name', 'extension', 'partition'],
|
|
'search' => ['category', 'partition', 'file_type'],
|
|
];
|
|
|
|
/**
|
|
* 验证文件上传
|
|
*/
|
|
public function sceneUpload()
|
|
{
|
|
return $this->append('file_name', 'require|max:255')
|
|
->append('file_path', 'require|max:500')
|
|
->append('file_size', 'require|integer|gt:0')
|
|
->append('file_type', 'require|max:100')
|
|
->append('category', 'require|max:50')
|
|
->append('original_name', 'max:255')
|
|
->append('extension', 'max:20')
|
|
->append('partition', 'max:50')
|
|
->append('upload_ip', 'ip')
|
|
->append('user_agent', 'max:500');
|
|
}
|
|
|
|
/**
|
|
* 验证文件信息更新
|
|
*/
|
|
public function sceneUpdateInfo()
|
|
{
|
|
return $this->append('file_name', 'require|max:255')
|
|
->append('category', 'require|max:50')
|
|
->append('original_name', 'max:255');
|
|
}
|
|
} |