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.

Thanks

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

Hi

  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',

				//'action'=>'addspecialevent',

                            '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');

            $model->image->saveAs('upload/coupon/'.$model->image);

Hope it may helpful

Hi modi,

first of all thanks for ur reply.

I found the solution based on this URL:

http://www.yiiframework.com/wiki/349/how-to-upload-image-photo-and-path-entry-in-database-with-update-functionality/

its really works for me.

Anyhow thanks again.

:lol: :D