Is it possible to validate an uploaded file using the CFileValidator without using a model? I have been trying to use this validator for dynamic upload file type purposes but i keep getting erros such as "Property "CFileValidator.0" is not defined." or some attribute is not defined in the CFileValidator Class model.
I can use vanilla php to validate the file types on upload, but i would prefer using a Yii defined method which satisfies the consumption of the framework.
Sample Code
//Using a Model Sends the CFileValidator.0" is not defined. Error
$params = array('image', 'file', 'types'=>'jpg,png,jpeg,gif,pjpeg','allowEmpty'=>true,'maxSize'=>10240,'wrongType'=>'File Type Not Accepted','tooLarge'=>'File too large! 10MB is the limit');
$validator= CValidator::createValidator('file', $personForm, 'image', $params);
$personForm->image = $_FILES['image'];
$file = CUploadedFile::getInstance($personForm,'image');
I made a complete change to the approach for executing the validation but for some strange reason The validator will not go into the validated true block.
$model = new Person();
$validator = CValidator::createValidator('file', $model, 'image',array('safe'=>true, 'types'=>array('jpg','jpeg'),'maxSize'=>10240));
$model->image = CUploadedFile::getInstanceByName('image');
if($validator->validate($model,'image')){
print_r(123);
}
else{
print_r($model->image);
}