Sarvar Nishonboyev
Sarvar Nishonboyev

Reputation: 13110

file type strtolower in yii validation

Is there any way to transform file type format to lower cases in yii form validation. For example, JPG => jpg, PNG => png. Even, I added image file formats in capital in validation rules, but it is still saying invalide file format.

Here's my validation rule:

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

Upvotes: 0

Views: 419

Answers (1)

Sudhir Bastakoti
Sudhir Bastakoti

Reputation: 100195

Extension names are case insensitive in CFileValidator, so you can just add in lowercase extension names, you could also add mimeTypes for proper validation, as,

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

Upvotes: 1

Related Questions