[b]CMultiFileUpload Works well when am using direct controller action view…
But i want to use CJuiDialog widget with ajaxlink for popup form 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…[/b]
[size="3"] Here is my Code:[/size]
<?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'); ?>
[size="3"]And this is my controller[/size]
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));
}
}
if( Yii::app()->request->isAjaxRequest )
{
Yii::app()->clientScript->scriptMap['jquery.js'] = false;
$this->renderPartial('create',array('model'=>$model),false,true);
}
[size="3"]And this is my view _form[/size]
<?php $form=$this->beginWidget('CActiveForm', array(
'id'=>'gallery-form',
'enableAjaxValidation'=>true,
'htmlOptions' => array(
'enctype' => 'multipart/form-data',),
)); ?>
<table width="100%" cellpadding="0" cellspacing="0" border="0">
<tr>
<td valign="top">
<!--<p class="note">Fields with <span class="required">*</span> are required.</p>-->
<p class="note">Choose images to upload then click upload.</p>
<?php echo $form->errorSummary($model); ?>
<!-- <div class="row">
<?php echo $form->labelEx($model,'user_id'); ?>
<?php echo $form->textField($model,'user_id'); ?>
<?php echo $form->error($model,'user_id'); ?>
</div>-->
<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->textField($model,'image',array('size'=>60,'maxlength'=>255)); ?>
<?php echo $form->error($model,'image'); ?>
</div>