【问题标题】:file type strtolower in yii validationyii 验证中的文件类型 strtolower
【发布时间】:2015-01-13 23:17:18
【问题描述】:

有没有办法在 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 !!!'),

【问题讨论】:

标签: php validation yii


【解决方案1】:

CFileValidator 中的扩展名不区分大小写,因此您可以只添加小写的扩展名,也可以添加mimeTypes 以进行正确验证,如,

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 !!!'
)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-02-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多