File Upload User's Crud

Hi there!, I’m trying to implement a file uploader (4 pdfs) on my User’s CRUD, my tablet tbl_users is id, username, password, email, pdf1, pdf2, pdf3, pdf4, I just downloaded the extension called coco but I can’t make it send those vars that I need (filename and User’s ID which I’m editing) on Users/Update action, can anyone help me clarify this? I wanna update those new fields (pdf1, pdf2, pdf3, pdf4) with new filepaths but I can’t find a way to get those vars on my action.

Here’s a piece of the code I’m using to upload multiple images, but it will work with other files. I save each file in a row in my table, different of you. I tried to adapt for you.


public function actionCreate()


$model=new YourModel;




            $files = CUploadedFile::getInstancesByName('files_');

            if (isset($files) && count($files) > 0) {

                $i=1; foreach ($files as $file => $f) {


                    // set folder

                    $folder = Yii::getPathOfAlias('webroot').'/folder');

                    if(!is_dir($folder)) {




                    $ext = pathinfo($f->name, PATHINFO_EXTENSION);

                    $model->pdf.$i = $f->name.'.'.$ext; //set you pdf1, pdf2, pdf3...

                    $pdfFile = $folder.'/'.$model->pdf.$i; 

                        if (!$f->saveAs($pdfFile)) { // **save them first

                            Yii::app()->user->setFlash('msg','File not save in HD');






                Yii::app()->user->setFlash('msg','File not save in BD');






VIEW: file field in form (this code I got here in forum, but I don’t remember the author.)

<?php $this->widget('CMultiFileUpload', array(

        'model' => $model,

        'name' => 'files_',

        'attribute' => 'files_',

        'accept' => 'jpeg|jpg|gif|png|bmp', // useful for verifying files

        'duplicate' => 'Dulicated!', // useful, i think

        'denied' => 'Invalid type of file', // useful, i think

        'max' => 20,

        'htmlOptions' => array('multiple'=>'multiple'),

    )); ?>


public $files_;

I it’s just an example, I hope it helps.

**I prefer save the data in BD first, them save the files in server.

Review this code first, it definitely has errors.