Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/271.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php yii验证中的文件类型strtolower_Php_Validation_Yii - Fatal编程技术网

Php yii验证中的文件类型strtolower

Php yii验证中的文件类型strtolower,php,validation,yii,Php,Validation,Yii,在yii表单验证中,是否有任何方法可以将文件类型格式转换为小写。例如,JPG=>JPG,PNG=>PNG。 甚至,我在验证规则中添加了大写的图像文件格式,但它仍然表示文件格式无效 以下是我的验证规则: array('photo','filter','filter'=>'strtolower'), array('photo', 'file', 'types' => 'JPG,jpg,jpeg,JPEG,gif,GIF,png,PNG', 'allowEmpty' => true,

在yii表单验证中,是否有任何方法可以将文件类型格式转换为小写。例如,JPG=>JPG,PNG=>PNG。 甚至,我在验证规则中添加了大写的图像文件格式,但它仍然表示文件格式无效

以下是我的验证规则:

array('photo','filter','filter'=>'strtolower'),
array('photo', 'file', 'types' => 'JPG,jpg,jpeg,JPEG,gif,GIF,png,PNG', 'allowEmpty' => true, 'maxSize' => 1024 * 1024 * 2,
                'tooLarge' => 'Size should be less then 2MB !!!'),

扩展名在中不区分大小写,因此您可以只添加小写扩展名,也可以添加以进行适当的验证,如下所示:

array('photo', 'file', 
    'types' => 'jpg, jpeg, gif, png', 
    'allowEmpty' => true, 
    'mimeTypes' => 'image/gif, image/jpeg, image/png'
    'wrongMimeType' => 'Invalid mime type',
    'maxSize' => 1024 * 1024 * 2,
    'tooLarge' => 'Size should be less then 2MB !!!'
)

扩展名不区分大小写。所以jpg也应该接受jpg。。见: