Image Rules Applying Order

Hi,

I have an image upload in the application and expects to check the rule in this order.

  1. Other than image type, show image type error.

  2. Size > 1MB, show size error.

The rule is as follows:




array('ImagePath', 'file','allowEmpty'=>true,'types'=>'jpg, gif, png,jpeg',  'wrongType' => Yii::t('error','Logo file type should be JPG, GIF or PNG'),'maxSize' => 1048576,'tooLarge' => Yii::t('error','Logo file size should be less than 1 MB')),



Now if I upload a 2MB size PDF file, I expect to show error "Logo file type should be JPG, GIF or PNG".But it is throwing

the error for size “'Logo file size should be less than 1 MB”.

How can I handle the rule to give preference to rule in order image type and then image size respectively?

The simplest way, I suppose, is to split image validation into two rules, putting image type validation first.

The second way - is to write your custom validator based on CFileValidator and to overwrite validateFile() method.