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;

       

		if(isset($_POST['lan']))

		{ 

			$model->attributes=$_POST['lan'];

              $model->lan_flag=CUploadedFile::getInstance($model,'lan_flag');

print_r($_POST);

            print_r($model); exit();

			if($model->save())

				$this->redirect(array('show','id'=>$model->lan_code));

		}

		$this->render('create',array('model'=>$model));

	}

form


<?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>


<div class="simple">

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

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

</div>


<div class="action">

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

</div>


<?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?

Dimis

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