<?php $form=$this->beginWidget('CActiveForm', array( 'id'=>'examen-form', 'enableAjaxValidation'=>false, 'htmlOptions' => array('enctype' => 'multipart/form-data'), )); ?>
and this is the widget and parameters used for CMultiFileUpload:
<div class="row"> <?php echo $form->labelEx($model,'archivo_foto')?> <?php //echo CHtml::activeFileField($model,'archivo_foto')?> <?php $this->widget('CMultiFileUpload', array( 'model' => $model, 'name' => 'archivo_foto', 'accept' => 'jpeg|jpg|gif|png|txt', // useful for verifying files 'duplicate' => 'Duplicate file!', // useful, i think 'denied' => 'Invalid file type', // useful, i think 'max' => 10, 'htmlOptions' => array( 'multiple' => 'multiple', 'size' => 25 ), )); ?> <?php echo $form->error($model,'archivo_foto')?> </div>
On the other hand, the controller action is implemented this way:
public function actionUpdateam($id) { $model=$this->loadModel($id); $dir=Yii::getPathOfAlias('application.uploads'); $model->archivo_documento='funciona 0'; if(isset($_POST['Examen'])) { $model->attributes=$_POST['Examen']; // THIS is how you capture those uploaded images: remember that in your CMultiFile widget, you set 'name' => 'archivo_foto' $images = CUploadedFile::getInstancesByName('archivo_foto'); // proceed if the images have been set $model->archivo_documento='funciona uno'; if (isset($images) && count($images) > 0) { $model->archivo_documento='funciona dos'; // go through each uploaded image foreach ($images as $image) { echo $image->name.'<br />'; $image->saveAs($dir.'/'.$image->name); $model->archivo_foto = $model->archivo_foto."+".$image->name; } // save the rest of your information from the form if ($model->save()) { $this->redirect(array('view','id'=>$model->id)); } } } $this->render('update_am',array( 'model'=>$model, )); }
And at last, I think that is important to mention the rule used for the model (it might be the cause of the problem as well):
array('archivo_documento, archivo_foto','file','allowEmpty'=>true,'maxFiles'=>10),
Also, I have followed directions of this page, without any success.
I think that the problem is in post method, because the controller is not uploading the files and is not making any changes in the database.