kalpit
(Panditkalpit)
October 4, 2013, 11:08am
1
hi i am doing multiple file upload…
i have setup form to use multiple file upload like this…
myfrom.php
<?php $form=$this->beginWidget('CActiveForm', array(
'id'=>'topic-form',
'enableAjaxValidation'=>false,
'htmlOptions' => array('enctype' => 'multipart/form-data'), // ADD THIS
)); ?>
<div class="row">
<?php
$this->widget('CMultiFileUpload', array(
'name' => 'imagepath',
'model'=> $model,
'id'=>'imagepath',
'accept' => 'jpeg|jpg|gif|png', // useful for verifying files
'duplicate' => 'Duplicate file!', // useful, i think
'denied' => 'Invalid file type', // useful, i think
));
?>
<div class="row buttons">
<?php echo CHtml::submitButton($model->isNewRecord ? 'Create' : 'Save'); ?>
</div>
</div>
<?php $this->endWidget(); ?>
and my controller method looks like…
public function actionMultipleupload()
{
$model= new Uploadimage();
if(isset($_POST['Uploadimage']))
{
var_dump("inside if");
// $images = CUploadedFile::getInstancesByName('images');
}
var_dump("out side if");
$this->render('multipleupload',array('model'=>$model));
}
but it’s going inside if loop only if i am using Multiple file upload widget …
it’s working fine with single file upload (shown below) and uploading also… but it showing problem in multiple file upload…
<div class="row">
<?php echo $form->labelEx($model,'imagepath'); ?>
<?php echo CHtml::activeFileField($model,'imagepath',array('size'=>60,'maxlength'=>500)); ?>
<?php echo $form->error($model,'imagepath'); ?>
</div>
i don’t what’s going wrong with my code… i am referringThis Post
Ankit_Modi
(Ankit Modi)
October 4, 2013, 11:45am
2
Hi,
what should be error generated?
kalpit
(Panditkalpit)
October 4, 2013, 11:59am
3
it’s not going inside if() condition only. so that mean it’s not getting value from form i think…
it’s not showing any error only
Ankit_Modi
(Ankit Modi)
October 4, 2013, 12:36pm
4
Hi I think you may write
if(isset($_POST[‘Uploadimage’])) && !empty ($_POST[‘Uploadimage’])
or image not in $_POST it’s $_FILES
I post the my demo exmple so i hope it’s some help.
try this in controller
if(isset($_POST['Uploadimage'])) && !empty ($_POST['Uploadimage']){
$images = CUploadedFile::getInstancesByName('image_name');
$this->actioninsertDB($images);
}
and create the function on controller
public function actioninsertDB($images) {
if (isset($images) && count($images) > 0) {
// make the directory to store the pic:
foreach ($images as $image => $pic) {
//echo $pic->name.'<br />';
$imagegalleryname = rand(0, 9999) . '_' . time() . strstr($pic->name, '.');
if ($pic->saveAs(Yii::getPathOfAlias('webroot') . '/upload/venue_gallery/' . $imagegalleryname)) {
// add it to the main model now
$img_add = new VenueGalllery();
$img_add->image_name = $imagegalleryname; //it might be $img_add->name for you, filename is just what I chose to call it in my model
$img_add->save(false); // this links your picture model to the main model (like your user, or profile model)
} else {
// handle the errors here, if you want
}
}
// go through each uploaded image
}
}
kalpit
(Panditkalpit)
October 4, 2013, 12:45pm
5
if(isset($_FILES('Uploadimage'])){
$images = CUploadedFile::getInstancesByName('imagepath');
print_r($images);
}
it’s also not working and i tried
if(isset($_POST['Uploadimage']) && !empty ($_POST['Uploadimage']))
{
$images = CUploadedFile::getInstancesByName('image_name');
print_r($images);
}
but not worked
Ankit_Modi
(Ankit Modi)
October 4, 2013, 12:51pm
6
kalpit:
if(isset($_FILES('Uploadimage'])){
$images = CUploadedFile::getInstancesByName('imagepath');
print_r($images);
}
it’s also not working and i tried
if(isset($_POST['Uploadimage']) && !empty ($_POST['Uploadimage']))
{
$images = CUploadedFile::getInstancesByName('image_name');
print_r($images);
}
but not worked
Hi I think you miss the attribute name on widgets
like
<?php
$this->widget('CMultiFileUpload', array(
'name' => 'image_name',
'attribute' => 'image_name',
'accept' => 'jpeg|jpg|png',
'max' => $max,
'duplicate' => 'file appears twice',
'remove' => Yii::t('ui', 'Remove'),
'htmlOptions' => array('disabled' => $disabled),
));
?>
please try it.
kalpit
(Panditkalpit)
October 4, 2013, 12:52pm
7
i attached my files for more details and my db field name is imagepath
kalpit
(Panditkalpit)
October 4, 2013, 12:55pm
8
that i have set as per my db_field
Ankit_Modi
(Ankit Modi)
October 4, 2013, 12:57pm
9
Hi i think you must be defind the action on page like
<?php
$form=$this->beginWidget('CActiveForm', array(
'id'=>'topic-form',
'action'=>'your_action'//please defind
'enableAjaxValidation'=>false,
'htmlOptions' => array('enctype' => 'multipart/form-data','multiple'=>'multiple'), // ADD THIS
));
?>
I hope it’s solve.
kalpit
(Panditkalpit)
October 4, 2013, 1:05pm
10
Hi i think you must be defind the action on page like
<?php
$form=$this->beginWidget('CActiveForm', array(
'id'=>'topic-form',
'action'=>'your_action'//please defind
'enableAjaxValidation'=>false,
'htmlOptions' => array('enctype' => 'multipart/form-data','multiple'=>'multiple'), // ADD THIS
));
?>
I hope it’s solve.
Still same… no change… where it’s going wrong i am identifying only… from last 3 hrs i am breaking my head behind it
Ankit_Modi
(Ankit Modi)
October 5, 2013, 3:30am
11
Hi,can you post the print_r($_FILES) array?
kalpit
(Panditkalpit)
October 5, 2013, 11:58am
12
Array
(
[imagepath] => Array
(
[name] => Array
(
[0] => CBI Janch honi chahiye.jpg
[1] => mummy ko bolo zaher pilaye.jpg
)
[type] => Array
(
[0] => image/jpeg
[1] => image/jpeg
)
[tmp_name] => Array
(
[0] => C:\xampp\tmp\phpE2C2.tmp
[1] => C:\xampp\tmp\phpE2C3.tmp
)
[error] => Array
(
[0] => 0
[1] => 0
)
[size] => Array
(
[0] => 7119
[1] => 6453
)
)
)
1