此验证行不起作用.我可以上传任何尺寸的图像.
['image', 'image', 'minWidth' => 250, 'maxWidth' => 250,'minHeight' => 250, 'maxHeight' => 250],
在控制器中,我使用.
$image = UploadedFile::getInstance($this, 'image');
解决方法:
就我所见,最后一行没有任何问题.
https://github.com/yiisoft/yii2/blob/master/docs/guide/tutorial-core-validators.md#yiivalidatorsimagevalidatorimage-
但是你要两次声明图像属性的规则 – 一个作为文件,一个作为图像.图像验证器从文件验证器扩展,因此它继承了它的所有属性.
Image Validator (docs):
This validator checks if the input value represents a valid image file. It extends from the file validator and thus inherits all its properties. Besides, it supports the following additional properties specific for image validation purpose:
尝试将其合并到一个规则中,看看是否有帮助.
[
'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
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。