Hi there. I’m trying to implement a multiple file upload. I followed some online tutorial and my end result is all files are uploaded to the directory but only no record is being saved.
Here is my Image model validation rules
array('path', 'file', 'types'=>'jpg, gif, png'),
array('path', 'file', 'allowEmpty'=>true, 'maxFiles'=>5),
In my form view I have the following widget in place
<?php echo $form->labelEx($image, 'path'); ?>
<?php $this->widget('CMultiFileUpload',array(
'model'=>$image,
'attribute'=>'path',
'accept'=>'png|jpg|gif',
'denied'=>'Only .png ,.jpg and .gif images are allowed.',
'max'=>5,
'remove'=>'[x]',
'duplicate'=>'You have already selected this file.',
));?>
<?php echo $form->error($image, 'path'); ?>
And lastly in my controller
$images=CUploadedFile::getInstances($image,"path");
foreach ($images as $i => $pic) {
if ($pic->saveAs(Yii::getPathOfAlias('webroot').'/files/'.$pic->name)) {
$image->post_id=$model->id;
$image->path=$pic->name;
$image->validate();
$image->save();
}
}
Now, if I set
save()
to
$image->save(false);
, it will only save one record.
I also tried dumping out the data of uploaded files and it shows all files. Am I missing something here?
Thanks.