/** * {@inheritDoc} * @see CFileValidator::validateAttribute() */ protected function validateAttribute($object, $attribute) { parent::validateAttribute($object, $attribute); $file = CUploadedFile::getInstance($object, $attribute); if ($file === null) { return; } $info = @getimagesize($file->getTempName()); if ($info === false) { $message = $this->wrongType ? $this->wrongType : Yii::t('yii', 'The file "{file}" cannot be uploaded. Only image files are allowed.'); $this->addError($object, $attribute, $message, array('{file}' => CHtml::encode($file->getName()))); return; } if (isset($this->minWidth)) { if ($info[0] < $this->minWidth) { $message = $this->tooNarrowWidth ? $this->tooNarrowWidth : Yii::t('photo.validator', 'The image "{file}" should be at least {minWidth}px in width.'); $this->addError($object, $attribute, $message, array('{file}' => CHtml::encode($file->getName()), '{minWidth}' => $this->minWidth)); } } if (isset($this->maxWidth)) { if ($info[0] > $this->maxWidth) { $message = $this->tooWideWidth ? $this->tooWideWidth : Yii::t('photo.validator', 'The image "{file}" should be at max {maxWidth}px in width.'); $this->addError($object, $attribute, $message, array('{file}' => CHtml::encode($file->getName()), '{maxWidth}' => $this->maxWidth)); } } if (isset($this->minHeight)) { if ($info[1] < $this->minHeight) { $message = $this->tooNarrowHeight ? $this->tooNarrowHeight : Yii::t('photo.validator', 'The image "{file}" should be at least {minHeight}px in height.'); $this->addError($object, $attribute, $message, array('{file}' => CHtml::encode($file->getName()), '{minHeight}' => $this->minHeight)); } } if (isset($this->maxHeight)) { if ($info[1] > $this->maxHeight) { $message = $this->tooWideHeight ? $this->tooWideHeight : Yii::t('photo.validator', 'The image "{file}" should be at max {maxheight}px in height.'); $this->addError($object, $attribute, $message, array('{file}' => CHtml::encode($file->getName()), '{maxheight}' => $this->maxHeight)); } } }
protected function validateAttribute($object, $attribute) { parent::validateAttribute($object, $attribute); }