I’m writing my custom ImageValidator class (extending CValidator).
The Filename is passed via the $attribute Parameter correctly.
However when calling functions such as
getimagesize()
I get the following error:
getimagesize(DS76HJ.jpg): failed to open stream: No such file or directory
here is my controller:
// Start Controller Fkt..
$model->avatar=CUploadedFile::getInstance($model,'avatar'); // get image object..
if($model->validate()) // Validate image..
{
// Do stuff is ok..
}
and here part of my ImageValidation class…
class ImageValidator extends CValidator
{
// ..Atts
protected function validateAttribute($object,$attribute)
{
// Init Stuff..
$value=$object->$attribute; // Objekt is of class user!!
if (getimagesize($value)) // put Image?? in getimagesize
{
// OK
}
else
{
// Error
$message=$this->message!==null?$this->message:Yii::t('yii','{attribute} File Validation failed - Save your image in MS Paint and try again!.',
array('{true}'=>$this->trueValue, '{false}'=>$this->falseValue));
$this->addError($object,$attribute,$message);
}
}
}