Cuploadedfile/filefield Problem


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…


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'); ?>



– Edit –

In this code…



 echo $model->trackGpsAC;

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

‘echo’ without this assignment

$model-> trackGpsAC

is null. But $ficGpx remains NULL with



I forgot in view file:

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

Now, works fine.