Yii 1.1: epicturevalidator

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

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;

Be the first person to leave a comment

Please to leave your comment.

Create extension