This extension extends CFileValidator, so it has its basic functionality plus we can validate photo's mime type, min height, min width, max height and max width.
protected/componentsSee the following code example:
public function rules() { return array( 'photo', 'EPhotoValidator', 'maxWidth'=>800, 'maxHeight'=>600, 'minWidth'=>100, 'minHeight'=>100 ); }
Another setting not shown above is mimeType which can be plain string with ie: image/jpeg or array of mime types:
public function rules() { return array( 'photo','EPhotoValidator','mimeType'=>array( 'image/jpeg','image/gif','image/png' )); }
For every setting there can be set an error message accessed by field settingError, like: minWidthError, mimeTypeError, maxHeightError etc:
return array( 'photo','EPhotoValidator','mimeType'=>array( 'image/jpeg','image/gif','image/png' ), 'mimeTypeError'=>'Only common types allowed');
Total 10 comments
thanks its work great.
here you can find some updated versions
Can this ext handle multiple uploads? Is there documentation on how to do this? Thanks!
replace line 96 of the validator to
$info=getimagesize($_FILES[get_class($object)]['tmp_name'][$attribute]);
to let it run on newer PHP Versions.
Yii ppl, would you please update http://www.yiiframework.com/extension/ephotovalidator/ with the vladm version?
See forum to get new extension version
I have download the phiras's version and found that it would not work with multiple uploaded files. CUploadedFile, that was extended by this one, uses validateFile method to validate the one uploaded file, and validateAttribute to validate entire attribute, thus to fix this problem you should move additional validation from validateAttribute method to validateFile.
Thanks for the good work, actually I did update the validator to cover all the bugs found by waylex, and I added some new things. please have a look here.
Greetings,
Firas
so simple...
Leave a comment
Please login to leave your comment.