Class yii\validators\ImageValidator

Inheritanceyii\validators\ImageValidator » yii\validators\FileValidator » yii\validators\Validator » yii\base\Component » yii\base\BaseObject
Implementsyii\base\Configurable
Available since version2.0
Source Code https://github.com/yiisoft/yii2/blob/master/framework/validators/ImageValidator.php

ImageValidator verifies if an attribute is receiving a valid image.

Public Properties

Hide inherited properties

PropertyTypeDescriptionDefined By
$attributes array|string Attributes to be validated by this validator. yii\validators\Validator
$builtInValidators array List of built-in validators (name => class or configuration) yii\validators\Validator
$checkExtensionByMimeType boolean Whether to check file type (extension) with mime-type. yii\validators\FileValidator
$enableClientValidation boolean Whether to enable client-side validation for this validator. yii\validators\Validator
$except array|string Scenarios that the validator should not be applied to. yii\validators\Validator
$extensions array|string A list of file name extensions that are allowed to be uploaded. yii\validators\FileValidator
$isEmpty callable A PHP callable that replaces the default implementation of isEmpty(). yii\validators\Validator
$maxFiles integer The maximum file count the given attribute can hold. yii\validators\FileValidator
$maxHeight integer The maximum width in pixels. yii\validators\ImageValidator
$maxSize integer The maximum number of bytes required for the uploaded file. yii\validators\FileValidator
$maxWidth integer The maximum width in pixels. yii\validators\ImageValidator
$message string The error message used when a file is not uploaded correctly. yii\validators\FileValidator
$mimeTypes array|string A list of file MIME types that are allowed to be uploaded. yii\validators\FileValidator
$minFiles integer The minimum file count the given attribute can hold. yii\validators\FileValidator
$minHeight integer The minimum height in pixels. yii\validators\ImageValidator
$minSize integer The minimum number of bytes required for the uploaded file. yii\validators\FileValidator
$minWidth integer The minimum width in pixels. yii\validators\ImageValidator
$notImage string The error message used when the uploaded file is not an image. yii\validators\ImageValidator
$on array|string Scenarios that the validator can be applied to. yii\validators\Validator
$overHeight string The error message used when the image is over $maxHeight. yii\validators\ImageValidator
$overWidth string The error message used when the image is over $maxWidth. yii\validators\ImageValidator
$skipOnEmpty boolean Whether this validation rule should be skipped if the attribute value is null or an empty string. yii\validators\Validator
$skipOnError boolean Whether this validation rule should be skipped if the attribute being validated already has some validation error according to some previous rules. yii\validators\Validator
$tooBig string The error message used when the uploaded file is too large. yii\validators\FileValidator
$tooFew string The error message used if the count of multiple uploads less that minFiles. yii\validators\FileValidator
$tooMany string The error message used if the count of multiple uploads exceeds limit. yii\validators\FileValidator
$tooSmall string The error message used when the uploaded file is too small. yii\validators\FileValidator
$underHeight string The error message used when the image is under $minHeight. yii\validators\ImageValidator
$underWidth string The error message used when the image is under $minWidth. yii\validators\ImageValidator
$uploadRequired string The error message used when no file is uploaded. yii\validators\FileValidator
$when callable A PHP callable whose return value determines whether this validator should be applied. yii\validators\Validator
$whenClient string A JavaScript function name whose return value determines whether this validator should be applied on the client-side. yii\validators\Validator
$wrongExtension string The error message used when the uploaded file has an extension name that is not listed in $extensions. yii\validators\FileValidator
$wrongMimeType string The error message used when the file has an mime type that is not allowed by $mimeTypes property. yii\validators\FileValidator

Public Methods

Hide inherited methods

MethodDescriptionDefined By
__call() Calls the named method which is not a class method. yii\base\Component
__clone() This method is called after the object is created by cloning an existing one. yii\base\Component
__construct() Constructor. yii\base\BaseObject
__get() Returns the value of a component property. yii\base\Component
__isset() Checks if a property is set, i.e. defined and not null. yii\base\Component
__set() Sets the value of a component property. yii\base\Component
__unset() Sets a component property to be null. yii\base\Component
addError() Adds an error about the specified attribute to the model object. yii\validators\Validator
attachBehavior() Attaches a behavior to this component. yii\base\Component
attachBehaviors() Attaches a list of behaviors to the component. yii\base\Component
behaviors() Returns a list of behaviors that this component should behave as. yii\base\Component
canGetProperty() Returns a value indicating whether a property can be read. yii\base\Component
canSetProperty() Returns a value indicating whether a property can be set. yii\base\Component
className() Returns the fully qualified name of this class. yii\base\BaseObject
clientValidateAttribute() {@inheritdoc} yii\validators\ImageValidator
createValidator() Creates a validator object. yii\validators\Validator
detachBehavior() Detaches a behavior from the component. yii\base\Component
detachBehaviors() Detaches all behaviors from the component. yii\base\Component
ensureBehaviors() Makes sure that the behaviors declared in behaviors() are attached to this component. yii\base\Component
getAttributeNames() Returns cleaned attribute names without the ! character at the beginning. yii\validators\Validator
getBehavior() Returns the named behavior object. yii\base\Component
getBehaviors() Returns all behaviors attached to this component. yii\base\Component
getClientOptions() {@inheritdoc} yii\validators\ImageValidator
getSizeLimit() Returns the maximum size allowed for uploaded files. yii\validators\FileValidator
getValidationAttributes() Returns a list of attributes this validator applies to. yii\validators\Validator
hasEventHandlers() Returns a value indicating whether there is any handler attached to the named event. yii\base\Component
hasMethod() Returns a value indicating whether a method is defined. yii\base\Component
hasProperty() Returns a value indicating whether a property is defined for this component. yii\base\Component
init() {@inheritdoc} yii\validators\ImageValidator
isActive() Returns a value indicating whether the validator is active for the given scenario and attribute. yii\validators\Validator
isEmpty() {@inheritdoc} yii\validators\FileValidator
off() Detaches an existing event handler from this component. yii\base\Component
on() Attaches an event handler to an event. yii\base\Component
trigger() Triggers an event. yii\base\Component
validate() Validates a given value. yii\validators\Validator
validateAttribute() {@inheritdoc} yii\validators\FileValidator
validateAttributes() Validates the specified object. yii\validators\Validator

Protected Methods

Hide inherited methods

MethodDescriptionDefined By
formatMessage() Formats a mesage using the I18N, or simple strtr if \Yii::$app is not available. yii\validators\Validator
getMimeTypeByFile() Get MIME type by file path yii\validators\FileValidator
validateExtension() Checks if given uploaded file have correct type (extension) according current validator settings. yii\validators\FileValidator
validateImage() Validates an image file. yii\validators\ImageValidator
validateMimeType() Checks the mimeType of the $file against the list in the $mimeTypes property. yii\validators\FileValidator
validateValue() {@inheritdoc} yii\validators\ImageValidator

Property Details

$maxHeight public property

The maximum width in pixels. Defaults to null, meaning no limit.

See also $overHeight for the customized message used when image height is too big.

public integer $maxHeight null
$maxWidth public property

The maximum width in pixels. Defaults to null, meaning no limit.

See also $overWidth for the customized message used when image width is too big.

public integer $maxWidth null
$minHeight public property

The minimum height in pixels. Defaults to null, meaning no limit.

See also $underHeight for the customized message used when image height is too small.

public integer $minHeight null
$minWidth public property

The minimum width in pixels. Defaults to null, meaning no limit.

See also $underWidth for the customized message used when image width is too small.

public integer $minWidth null
$notImage public property

The error message used when the uploaded file is not an image. You may use the following tokens in the message:

  • {attribute}: the attribute name
  • {file}: the uploaded file name
public string $notImage null
$overHeight public property

The error message used when the image is over $maxHeight. You may use the following tokens in the message:

  • {attribute}: the attribute name
  • {file}: the uploaded file name
  • {limit}: the value of $maxHeight
public string $overHeight null
$overWidth public property

The error message used when the image is over $maxWidth. You may use the following tokens in the message:

  • {attribute}: the attribute name
  • {file}: the uploaded file name
  • {limit}: the value of $maxWidth
public string $overWidth null
$underHeight public property

The error message used when the image is under $minHeight. You may use the following tokens in the message:

  • {attribute}: the attribute name
  • {file}: the uploaded file name
  • {limit}: the value of $minHeight
public string $underHeight null
$underWidth public property

The error message used when the image is under $minWidth. You may use the following tokens in the message:

  • {attribute}: the attribute name
  • {file}: the uploaded file name
  • {limit}: the value of $minWidth
public string $underWidth null

Method Details

clientValidateAttribute() public method

{@inheritdoc}

public void clientValidateAttribute ( $model, $attribute, $view )
$model
$attribute
$view
getClientOptions() public method

{@inheritdoc}

public void getClientOptions ( $model, $attribute )
$model
$attribute
init() public method

{@inheritdoc}

public void init ( )
validateImage() protected method

Validates an image file.

protected array|null validateImage ( $image )
$image yii\web\UploadedFile

Uploaded file passed to check against a set of rules

return array|null

The error message and the parameters to be inserted into the error message. Null should be returned if the data is valid.

validateValue() protected method

{@inheritdoc}

protected void validateValue ( $value )
$value