Cuploadedfile/filefield Problem

Hello,

I have the next code in the model rules for the trackGpsAC field (upload GPS tracks):


array('trackGpsAC', 'file', 'types'=>'gpx', 'allowEmpty' => true),

First problem. If I don´t set allowEmpty (true) when I send the form, there is always an error (field empty), but isn´t a ‘required’ field ¿?

On the other hand, in the controller…




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

echo $_POST['Actividad']['trackGpsAC'];

$ficGpx = CUploadedFile::getInstance($model, 'trackGpsAC');



‘echo’ works fine and show the name of file .gpx properly, but $ficGPX is null always. I also tried with “getInstanceByName()” method but the same result.

In the view…





    <div class="row">

            <?php echo $form->labelEx($model,'trackGpsAC'); ?>

            <?php echo $form->fileField($model,'trackGpsAC',array('size'=>45,'maxlength'=>45)); ?>

            <?php echo $form->error($model,'trackGpsAC'); ?>

    </div>



Thanks.

– Edit –

In this code…


   

 $model->trackGpsAC=$_POST['Actividad']['trackGpsAC'];

 echo $model->trackGpsAC;

$ficGpx = CUploadedFile::getInstance($model, 'trackGpsAC');



‘echo’ without this assignment


$model-> trackGpsAC

is null. But $ficGpx remains NULL with


$model->trackGpsAC=$_POST['Actividad']['trackGpsAC'];

Ok.

I forgot in view file:


'htmlOptions' => array('enctype' => 'multipart/form-data'),

Now, works fine.