* @link http://www.yiiframework.com/ * @copyright Copyright © 2008 Yii Software LLC * @license http://www.yiiframework.com/license/ */ /** * CFileValidator verifies if the attribute is receiving a valid uploaded file. * * * @author Qiang Xue * @version $Id$ * @package system.validators * @since 1.0 */ class CFileValidator extends CValidator { /** * @var boolean whether the attribute value can be null or empty. Defaults to true, * meaning that if the attribute is empty, it is considered valid. */ public $allowEmpty=true; /** * Validates the attribute of the object. * If there is any error, the error message is added to the object. * @param CModel the object being validated * @param string the attribute being validated */ protected function validateAttribute($object,$attribute) { $value=$object->$attribute; if($this->allowEmpty && ($value===null || $value==='')) return; $file=CUploadedFile::getInstance(get_class($object).'['.$attribute.']'); if(!$valid) { $message=$this->message!==null?$this->message:Yii::t('yii','{attribute} must be {type}.',array('{type}'=>$this->type)); $this->addError($object,$attribute,$message); } } }