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.
CONTROLLER:
public function actionCreate()
{
$model=new YourModel;
if(isset($_POST['YourModel']))
{
$model->attributes=$_POST['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)) {
mkdir($folder,0755,true);
}
$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');
}
$i++;
}
}
if(!model->save(){
Yii::app()->user->setFlash('msg','File not save in BD');
}
}
$this->render('create',array(
'model'=>$model,));
}
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'),
)); ?>
MODEL:
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.