Yii Framework Forum: Multiple File Upload - Yii Framework Forum

Jump to content

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

Multiple File Upload Rate Topic: -----

#1 User is offline   kalpit 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 152
  • Joined: 02-August 13
  • Location:Bangalore

Posted 04 October 2013 - 06:08 AM

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

This post has been edited by kalpit: 04 October 2013 - 06:17 AM

Thanks,
Kalpit Pandit
0

#2 User is offline   Ankit Modi 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 893
  • Joined: 19-February 13
  • Location:India

Posted 04 October 2013 - 06:45 AM

Hi,
what should be error generated?
Thanks,
Ankit Modi
Skype : amodi06
0

#3 User is offline   kalpit 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 152
  • Joined: 02-August 13
  • Location:Bangalore

Posted 04 October 2013 - 06:59 AM

View PostMaggie Q(Ankit Modi), on 04 October 2013 - 06:45 AM, said:

Hi,
what should be error generated?


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
Thanks,
Kalpit Pandit
0

#4 User is offline   Ankit Modi 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 893
  • Joined: 19-February 13
  • Location:India

Posted 04 October 2013 - 07:36 AM

View Postkalpit, on 04 October 2013 - 06:59 AM, said:

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


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
		}
	}

Thanks,
Ankit Modi
Skype : amodi06
0

#5 User is offline   kalpit 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 152
  • Joined: 02-August 13
  • Location:Bangalore

Posted 04 October 2013 - 07:45 AM

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
Thanks,
Kalpit Pandit
0

#6 User is offline   Ankit Modi 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 893
  • Joined: 19-February 13
  • Location:India

Posted 04 October 2013 - 07:51 AM

View Postkalpit, on 04 October 2013 - 07:45 AM, said:

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.
Thanks,
Ankit Modi
Skype : amodi06
1

#7 User is offline   kalpit 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 152
  • Joined: 02-August 13
  • Location:Bangalore

Posted 04 October 2013 - 07:52 AM

i attached my files for more details and my db field name is imagepath

Attached File(s)


Thanks,
Kalpit Pandit
0

#8 User is offline   kalpit 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 152
  • Joined: 02-August 13
  • Location:Bangalore

Posted 04 October 2013 - 07:55 AM

that i have set as per my db_field
Thanks,
Kalpit Pandit
0

#9 User is offline   Ankit Modi 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 893
  • Joined: 19-February 13
  • Location:India

Posted 04 October 2013 - 07:57 AM

View Postkalpit, on 04 October 2013 - 07:52 AM, said:

i attached my files for more details and my db field name is imagepath



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.
Thanks,
Ankit Modi
Skype : amodi06
0

#10 User is offline   kalpit 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 152
  • Joined: 02-August 13
  • Location:Bangalore

Posted 04 October 2013 - 08:05 AM

View PostMaggie Q(Ankit Modi), on 04 October 2013 - 07:57 AM, said:

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
Thanks,
Kalpit Pandit
0

#11 User is offline   Ankit Modi 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 893
  • Joined: 19-February 13
  • Location:India

Posted 04 October 2013 - 10:30 PM

View Postkalpit, on 04 October 2013 - 08:05 AM, said:

Still same... no change... where it's going wrong i am identifying only... from last 3 hrs i am breaking my head behind it



Hi,can you post the print_r($_FILES) array?
Thanks,
Ankit Modi
Skype : amodi06
0

#12 User is offline   kalpit 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 152
  • Joined: 02-August 13
  • Location:Bangalore

Posted 05 October 2013 - 06:58 AM

View PostMaggie Q(Ankit Modi), on 04 October 2013 - 10:30 PM, said:

Hi,can you post the print_r($_FILES) array?



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

Thanks,
Kalpit Pandit
0

#13 User is offline   Ankit Modi 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 893
  • Joined: 19-February 13
  • Location:India

Posted 06 October 2013 - 10:26 PM

View Postkalpit, on 05 October 2013 - 06:58 AM, said:

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




Hi please see forum

I hope it's some help.
Thanks,
Ankit Modi
Skype : amodi06
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