Check Yii2 Image Size

This check string does not work. I could upload images in any dimension.

['image', 'image', 'minWidth' => 250, 'maxWidth' => 250,'minHeight' => 250, 'maxHeight' => 250], 

in the controller i use.

 $image = UploadedFile::getInstance($this, 'image');
+4
source share
1 answer

As far as I can see, there is nothing wrong with the last line. https://github.com/yiisoft/yii2/blob/master/docs/guide/tutorial-core-validators.md#yiivalidatorsimagevalidatorimage-

But you declare the rules for the attribute imagetwice - one as a file and the other as an image. The image validator comes from the file validator, so it inherits all its properties.

Image Validator (documents):

, . , , . , , :

, .

[
     'image', 
     'image', 
     'minWidth' => 250, 
     'maxWidth' => 250,
     'minHeight' => 250, 
     'maxHeight' => 250, 
     'extensions' => 'jpg, gif, png', 
     'maxSize' => 1024 * 1024 * 2
],

: $model, , $model->image , .

: http://www.yiiframework.com/doc-2.0/guide-input-file-upload.html

+7

Source: https://habr.com/ru/post/1629304/


All Articles