Yii Framework Forum: Cmultifileupload - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Cmultifileupload CMultiFileUpload failed to save data into database Rate Topic: -----

#1 User is offline   aep 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 2
  • Joined: 03-January 13

Posted 06 January 2013 - 09:19 PM

Dear all

I need some help immediately, i have try CMultiFileUpload to upload multiple file into my database, but the problem is the file is store into directory but the database still empty, does anyone know why this happen?

herewith my form source:

<?php echo $form->labelEx($model,'attachment'); ?><br />
<?php $this->widget('CMultiFileUpload', array(
'name' => 'attachment',
'accept' => 'jpeg|jpg|gif|png|pdf|doc|docx|xlx|xlsx|zip|rar',
'duplicate' => 'Duplicate file!',
'remove'=>Yii::t('ui','Remove <--'),
'denied' => 'File Is Not Allowed, Upload Only: jpeg,jpg,gif,png,pdf,doc,docx,xlx,xlsx,zip,rar',
));?>
<?php echo $form->error($model,'attachment'); ?>


my model source:

array('attachment', 'file',
'types'=>'jpeg,jpg,gif,png,pdf,doc,docx,xlx,xlsx,zip,rar,rtf,ppt,pptx,txt', 'allowEmpty'=>true, 'on'=>'insert,update'),
array('title, attachment', 'length', 'max'=>255, 'on'=>'insert,update'),

and my controller source:

public function actionCreate()
{

$model=new Content;

// Uncomment the following line if AJAX validation is needed
// $this->performAjaxValidation($model);

if(isset($_POST['Content']))
{
$model->attributes=$_POST['Content'];
$images = CUploadedFile::getInstancesByName('attachment');
if(isset($images) && count($images) > 0)
{
foreach ($images as $i=>$ii)
{
//echo $ii ->name. '<br />';
if ($ii->saveAs(Yii::getPathOfAlias('webroot').'/images/'.$ii->name))
{
$img_add = new Content();
$img_add->attachment = $ii->name;
//$img_add->topic_id = $model->idpropinsi;
$img_add->save();
}
else
$img_add = new Content();
$img_add->attachment = $ii->name;
//$img_add->topic_id = $model->idpropinsi;
$img_add->save();
//}



if($model->save())
{
$this->redirect(array('view','id'=>$model->id));

}
}
}
}
$this->render('create',array(
'model'=>$model,
));

}

Somebody help me please, today is my deadline for my homework
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users