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.