views/_form.php.
<?php echo $form->labelEx($model,'image'); ?><br/>
<?php $this->widget('CMultiFileUpload', array(
'model' => $model,
'name' => 'image',
'accept' => 'jpeg|jpg|gif|png',
'duplicate' => 'File is not existed!',
'denied' => 'Not images', // useful,
'htmlOptions'=>array(
'class'=>'form-control'
),
)); ?>
<?php echo $form->error($model,'image'); ?>
Controller/
public function actionCreate()
{
$model = new Modelmu;
$images = CUploadedFile::getInstancesByName('image');
if($images !=null)
{
if(isset($_POST['Modelmu']))
$model->attributes=$_POST['Modelmu'];
foreach($images as $list=>$pic)
{
$webroot = Yii::getPathOfAlias('webroot');
$files = $webroot .'/images/';
$model->setIsNewRecord(true);
$model->id=null;
$model->image = $pic;
$model->save();
$model->image->saveAs($files);
}
$this->redirect(array('index'));
}
$this->render('create',array(
'model'=>$model,
));
}
silahkan di coba
<?php echo $form->labelEx($model,'image'); ?><br/>
<?php $this->widget('CMultiFileUpload', array(
'model' => $model,
'name' => 'image',
'accept' => 'jpeg|jpg|gif|png',
'duplicate' => 'File is not existed!',
'denied' => 'Not images', // useful,
'htmlOptions'=>array(
'class'=>'form-control'
),
)); ?>
<?php echo $form->error($model,'image'); ?>
Controller/
public function actionCreate()
{
$model = new Modelmu;
$images = CUploadedFile::getInstancesByName('image');
if($images !=null)
{
if(isset($_POST['Modelmu']))
$model->attributes=$_POST['Modelmu'];
foreach($images as $list=>$pic)
{
$webroot = Yii::getPathOfAlias('webroot');
$files = $webroot .'/images/';
$model->setIsNewRecord(true);
$model->id=null;
$model->image = $pic;
$model->save();
$model->image->saveAs($files);
}
$this->redirect(array('index'));
}
$this->render('create',array(
'model'=>$model,
));
}
silahkan di coba