epicturevalidator Validates uploaded file to be a valid image, optionally checks minimum image width and height

  1. Requirements
  2. Usage

Validates uploaded file to be a valid image, optionally checks minimum image width and height

Requirements

Yii 1.1 or above

Usage

Place EPictureValidator.php to any folder that your application imports.

Suppose your model has an attribute $pictureFile of type CUploadedFile. In your model class add 'file' validator and EPictureValidator to the rules() method like this:

class YourModel extends CFormModel
{
  
    /**
     * @var CUploadedFile Uploaded picture file
     */
    public $pictureFile;
    
    public function rules()
    {
        return array(
            array(
                'pictureFile',
                'file',
                'types' => 'gif, jpg, jpeg, png',
                'allowEmpty' => false
            ),
            array(
                'pictureFile',
                'EPictureValidator',
                'minWidth' => 200,
                'minHeight' => 200,
            ),
        );
    }
}

Use this validator in cooperation with CFileValidator, see above example, because it doesn't check for uploading errors;

5 0
8 followers
717 downloads
Yii Version: 1.1
License: BSD-2-Clause
Category: Validation
Tags: pictures
Developed by: Sergey Tsivin
Created on: Jul 15, 2011
Last updated: 12 years ago

Downloads

show all

Related Extensions