Upload image not working


(Rameshengginno) #1

Just i am start to learn yii. When i try to upload a image, i am getting empty value on submit.

This is my controller file code




public function actionCreate()

	{

        $model=new Upload;

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

        {

	  print_r($_POST['Upload']);    // it return file value is empty   


        }

        $this->render('create', array('model'=>$model));

	}



This is my model file code.





public function rules()

    {

        return array(

             array('file', 'file','types'=>'jpg, gif, png'),

	     array('file','safe'),

        );

    }



This is my view file code.




<div class="form">


<?php $form = $this->beginWidget(

    'CActiveForm',

    array(

        'id' => 'upload-form',

        'enableAjaxValidation' => false,

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

    )

); ?>


	<p class="note">Fields with <span class="required">*</span> are required.</p>


	<?php echo $form->errorSummary($model); ?>


	<div class="row">

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

		<?php echo $form->fileField($model, 'file'); ?>

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

	</div>


	<div class="row buttons">

		<?php echo CHtml::submitButton($model->isNewRecord ? 'Create' : 'Save'); ?>

	</div>


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



My getting result is




Array ( [file] => ) 



Plse resolve my issue. Thanks in advance


(Fabrizio Caldarelli) #2

Uploaded files are in $_FILES array, not in $_POST array.