Cmultifileupload Not Working

I’m working on multi file(images) uploading functionality.

All I’ve tried.

It’s not working.

Here’s my View’s snippet that may require




$this->widget('CMultiFileUpload', array(

        'model' => $model,

        'attribute' => 'sample',

        'accept' => 'jpeg|jpg|gif|png',

        'duplicate' => 'Duplicate file!',

        'denied' => 'Invalid file type',

        'remove' => '[x]',

        'max' => 20,

));



This is the controller’s code




if (isset($_POST['Bid'])) {

            $model->attributes = $_POST['Bid'];

            

            $photos = CUploadedFile::getInstancesByName('sample');

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


                foreach ($photos as $image => $pic) {

                    $pic->name;

                    if ($pic->saveAs(Yii::getPathOfAlias('webroot').'/images/'.$pic->name)) {

                        // add it to the main model now

                        $img_add = new Bid;

                        $img_add->filename = $pic->name; //it might be $img_add->name for you, filename is just what I chose to call it in my model

 

                        $img_add->save();

                    }

                    else {

                        

                    }

                }

            }


            $model->project_id = $project->id;

            $model->freelancer_id = $this->currentUser->id;

            if ($model->save()) {

                $this->redirect(array('project/view', 'id' => $project->id, '#' => 'bidslist'));

            }

        }


        $this->render('create', array(

            'model' => $model,

        ));

    }



I’ve some basic rules for the uploading images




public function rules() {

        return array(

            array('deadline_input', 'required'),

            array('sample', 'required', 'on' => 'insert'),

            array('sample', 'file', 'on' => 'insert', 'types' => 'png jpg jpeg gif', 'maxSize' => 2 * 1024 * 1024),

            array('sample', 'file', 'on' => 'update', 'types' => 'png jpg jpeg gif', 'allowEmpty' => true, 'maxSize' => 2 * 1024 * 1024),

            array('deadline_input', 'date', 'format' => self::DEADLINE_DATE_FORMAT),

        );

    }



Image’s names aren’t uploading on the database. Some images going on to the folder sometime.

It’s been a while I’ve trying to figure out the issue.

Thanks in Advance.


$model = new Bid(); // Hope you have already put it in you controller

$img_add = new Bid(); // should use () after model to instantiate



Please format your code before put any code segment.

Would you please paste your full controller code.

change something into your controller ::




$img_add = new Bid();



Thanks a lot.

Yap. Here’s my controller.

pastebindotcom/k1uf6Qnd

Also the error I"m getting is "Sample cannot be blank." sample used to be the database table name and the images attribute name on the model.

Means the images name isn’t inserting on the particular database column field.

Thanks.

Changing that didn’t work.

$img_add = new Bid();

Thanks.

Moved from Miscellaneous to General Discussion for Yii 1.1.x.