Yii Framework Forum: Problem Using Cmultifileupload For Uploading Files - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • This topic is locked

Problem Using Cmultifileupload For Uploading Files Rate Topic: -----

#1 User is offline   leonias 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 3
  • Joined: 15-February 13

Posted 27 May 2013 - 05:38 AM

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.

#2 User is offline   Saurabh Dhariwal 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 42
  • Joined: 27-September 13

Posted 08 July 2015 - 07:23 AM

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
Saurabh Dhariwal
Skype ID: dhariwal.saurabh

Share this topic:

Page 1 of 1
  • You cannot start a new topic
  • This topic is locked

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users