Cmultiuploadedfile Problem

there is aproblem with my code here

iam trying to make multi uploaded files(images)

but there is some thing wrong here :


My view :


<?php $form=$this->beginWidget('CActiveForm', array(

'id'=>'u-form',

	'enableClientValidation'=>true,

	'clientOptions'=>array(

	'validateOnSubmit'=>true,	

    'htmlOptions' => array( 'enctype' => 'multipart/form-data'),

),

)); ?>


   

     <?php echo $form->labelEx($model,'image'); ?>

        <?php

          $this->widget('CMultiFileUpload', array(

             'model'=>$model,

             'attribute'=>'image',

             'accept'=>'jpg|gif|png',

            ));

        ?>

        <?php echo $form->error($model,'image'); ?>

        

        

    <?php echo CHtml::submitButton( 'Submit'); ?>

    

   

<?php $this->endWidget(); ?>

____________________________________________________________________________________________

My controller:


	 	public function actionIndex()

	{

	  $model=new Photo();

        // Uncomment the following line if AJAX validation is needed

         //$this->performAjaxValidation($model);


        if(isset($_POST['Photo']))

        {

            $model->attributes=$_POST['Photo'];

			

            $images = CUploadedFile::getInstances($model,'iamge');

			var_dump($images);

            

            if(isset($images) && count($images)> 0) 

            {

            	

                foreach ($images as $image=>$pic) 

                {

                      if ($pic->saveAs(Yii::getPathOfAlias('webroot').'/images/'.$pic->name,0777))     

                    {    

                        $model->setIsNewRecord(true);

                        $model->id = null;

                        $model->image = $pic->name;

                        $model->save();

                    }                

                }

                        $this->redirect(array('view','id'=>$model->id));

            }

        }

        $this->render('index',array(

            'model'=>$model,

        ));	

	} 

whats wrong with that <img src='http://www.yiiframework.com/forum/public/style_emoticons/default/huh.gif' class='bbc_emoticon' alt='???' />

PS : var_dump($images);

gives me array(0) { }

and i don’t know why :angry:

First of all, it’s the post style. Plz use “code” tag for posting code examples, there’s a button up there.

If you do so, the code will become more readable, and you’ll find this:


$images = CUploadedFile::getInstances($model,'iamge');

Obviously "iamge" is not what you want.

thanks a lot and sorry for the bad style i will change it


$images = CUploadedFile::getInstances($model,'iamge');

this is not the problem but thnx i change it to image :rolleyes:

Seems like you’re doing it wrong.

Maybe this can help: http://www.yiiframework.com/wiki/176/uploading-multiple-images-with-cmultifileupload/

when i use the widget form this :


<?php $form=$this->beginWidget('CActiveForm', array(

    'id'=>'topic-form',

    'enableAjaxValidation'=>false,

    'htmlOptions' => array('enctype' => 'multipart/form-data'), // ADD THIS

)); ?>

there is no data were post by this form so i tried this


<?php echo CHtml::form('','post',array('enctype'=>'multipart/form-data')); ?>



no posting and var_dump($_POST[‘photo’]); gives me NULL

so i have to use this


<?php $form=$this->beginWidget('CActiveForm', array(

'id'=>'u-form',

	'enableClientValidation'=>true,

	'clientOptions'=>array(

	'validateOnSubmit'=>true,	

    'htmlOptions' => array( 'enctype' => 'multipart/form-data'),

),

)); ?>

cuz its the only one works with me and i don’t know why and still don’t know why

var_dump($images);

gives me an empty array :(

What about $_FILES?

do you mean :


 move_uploaded_file($_FILES["file"]["tmp_name"],

      "upload/" . $_FILES["file"]["name"]);

i can use this method if i want to upload one photo but how can i use it with CMultiFileUpload which sends an array with all selected photos using model and attribute and where can i use it here :




if(isset($_POST['Photo']))

{

$model->attributes=$_POST['Photo'];


$images = CUploadedFile::getInstances($model,'image');

var_dump($images);


if(isset($images) && count($images)> 0) 

{


foreach ($images as $image=>$pic) 

{

if ($pic->saveAs(Yii::getPathOfAlias('webroot').'/images/'.$pic->name,0777)) 

{ 

$model->setIsNewRecord(true);

$model->id = null;

$model->image = $pic->name;

$model->save();

}