file upload problem

I create with crud comand line the forms for the "lan" table ->lan_code,lan_flag.

lan_flag will be an image so I change a litle the code

The problem is that even I write something for code and a file for the image there is a validation error.

What is wrong?

actionCreate-validation rule etc

 public function rules()


        return array(

           array('lan_flag', 'required', 'on'=>'Create'),

            array('lan_flag', 'file', 'types'=>'jpg, gif, png'),

            array('lan_code', 'required'),



public function afterSave() {

    $caminhoArquivo = Yii::app()->basePath . '/file/' . $this->lan_flag;

    CUploadedFile::getInstance($this,'lan_flag')->saveAs($caminhoArquivo); }

public function actionCreate()


		$model=new lan;







            print_r($model); exit();







<?php echo CHtml::beginForm(array('method'=>'post','enctype'=>'multipart/form-data')); ?>

<?php echo CHtml::errorSummary($model); ?>

<div class="simple">

<?php echo CHtml::activeLabelEx($model,'lan_code'); ?>

<?php echo CHtml::activeTextField($model,'lan_code'); ?>


<div class="simple">

<?php echo CHtml::activeLabelEx($model,'lan_flag'); ?>

<?php echo CHtml::activeFileField($model,'lan_flag'); ?>


<div class="action">

<?php echo CHtml::submitButton($update ? 'Save' : 'Create'); ?>


<?php echo CHtml::endForm(); ?>

I manage to solve the problem, I want at update the file not to be required, how can I do that?Now if I set empty the file, the field will be null at table

Is there any method to resize the file at upload?


set "allowEmpty" option of your "file" validation rule to be true.