Problem Using Cmultifileupload For Uploading Files

I’m trying to implement a multiple file upload using CMultiFileUpload with CUploadedFile, but it doesn’t work. Specifically, _POST is not working even considering that I’m using ‘enctype’ => ‘multipart/form-data’ in the options in the view:

<?php $form=$this->beginWidget('CActiveForm', array(



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


On the other hand, the controller action is implemented this way:

        public function actionUpdateam($id)




                $model->archivo_documento='funciona 0';

                if(isset($_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 />';


                                        $model->archivo_foto = $model->archivo_foto."+".$image->name;



                                // save the rest of your information from the form

                                if ($model->save()) {










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.

I have reviewed your code and find a way out for this problem.

In your scenario, the rule of allowEmpty string conflicts with model field validation rules for ‘archivo_foto’ field. So you don’t have to add following rule in your model.

array('archivo_documento, archivo_foto','file','allowEmpty'=>true,'maxFiles'=>10),

If you want to go through your scenario, you need to make changes in your controller as below:


Let me know if you face any query/concern regarding this.


Saurabh Dhariwal