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;
If you have any questions, please ask in the forum instead.
Signup or Login in order to comment.