Am using CJuiDialog widget with ajaxlink for popup form..it works well..
But now i need to upload multiple files from that popup form.. so i use CMultiFileUpload for upload option but i acts like a normal single file button.. please help me to solve this.. Here is my Code:
<?php echo CHtml::ajaxLink(Yii::t('image','Upload'),array('gallery/create'),array(
'success'=>'js:function(data){
$("#gallery-form").dialog("open");
document.getElementById("add_images").innerHTML=data;}'));
$this->beginWidget('zii.widgets.jui.CJuiDialog',array(
'id'=>'gallery-form',
'options'=>array(
'title'=>Yii::t('image','Upload'),
'autoOpen'=>false,
'model'=>'true',
'width'=>'auto',
'height'=>'auto',
),
));
echo "<div id='add_images'></div>";
$this->endWidget('zii.widgets.jui.CJuiDialog'); ?>
and this is my controller action:
if(isset($_FILES['image']))
{
$model->attributes=$_POST['Photo'];
$images = CUploadedFile::getInstancesByName('image');
if(isset($images) && count($images)> 0)
{
foreach ($images as $image=>$pic)
{
if (!is_dir(Yii::getPathOfAlias('webroot').'/gallery/'.$user->username===true) ){
mkdir(Yii::getPathOfAlias('webroot').'/gallery/'.$user->username, 0777);
}
if ($pic->saveAs(Yii::getPathOfAlias('webroot').'/gallery/'.$user->username.'/'.$pic->name))
{
$model->setIsNewRecord(true);
$model->id = null;
$model->image = $pic->name;
$model->setAttribute('user_id',$id);
$model->save();
}
}
$this->redirect(array('admin','id'=>$model->id));
}
}
Ajax Popup Request
if( Yii::app()->request->isAjaxRequest )
{
Yii::app()->clientScript->scriptMap['jquery.js'] = false;
$this->renderPartial('create',array(
'model'=>$model,
));}else{}
This is my rendered partial view file which works fine with multiupload file without call with cjuidialog but when i call it with cjuidialog it just support only single file upload..Please help.
<?php $form=$this->beginWidget('CActiveForm', array(
'id'=>'gallery-form',
'enableAjaxValidation'=>true,
'htmlOptions' => array(
'enctype' => 'multipart/form-data',),
)); ?>
<?php echo $form->errorSummary($model); ?>
<div class="row">
<?php echo $form->labelEx($model,'image'); ?>
<?php
$this->widget('CMultiFileUpload', array(
'model'=>$model,
'name'=>'image',
'attribute'=>'image',
'accept'=>'jpg|gif|png',
));
?>
<?php echo $form->error($model,'image'); ?>
</div>
<div class="row buttons">
<?php echo CHtml::submitButton($model->isNewRecord ? 'Upload' : 'Save'); ?>
</div>
<?php $this->endWidget(); ?>