Yii Framework Forum: Upload image not working - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • This topic is locked

Upload image not working Rate Topic: -----

#1 User is offline   aark 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 5
  • Joined: 24-May 13

Posted 07 June 2015 - 09:28 AM

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
0

#2 User is offline   Fabrizio Caldarelli 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 1,059
  • Joined: 21-March 13
  • Location:Rome, Italy

Posted 07 June 2015 - 12:56 PM

Uploaded files are in $_FILES array, not in $_POST array.
Yii2 by example: my book about Yii2
https://www.packtpub...nt/yii2-example
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • This topic is locked

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users