Upload Image & Preview

Hi ter,

IM newbie to yii framework,

currently im doing registration form to make user upload their own photo & preview it before save into database.

pls provide me guidelines how to do this.


[color="#006400"]/* Moved from "Miscellaneous" to "General Discussion for Yii 1.1.x" */[/color]


  1. first change the filed in _form.php

 $form->fileField($model, 'image', array('maxlength' => 255)); 

  1. you can defind the ‘enctype’ => ‘multipart/form-data’ on $from array

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

                            'id' => 'regular-form',


                            'enableAjaxValidation' => false,

                            'enableClientValidation' => true,

                            'clientOptions' => array(

                                    'validateOnSubmit' => false,

				//'afterValidate' => "js:afterValidate",


                            'stateful' => false,

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


3)and then upload image on controller code

      $model->image = CUploadedFile::getInstance($model, 'image');


Hope it may helpful

Hi modi,

first of all thanks for ur reply.

I found the solution based on this URL:


its really works for me.

Anyhow thanks again.

:lol: :D