Preview An Image Before It Is Saved To Database In Yii Using Jquery

Hi all,

:unsure:

i m not understanding how should i carry on to Preview an image before it is being saved to database in yii using jquery or any method that you can suggest

[code]

view

 <img src="images/<?php echo $model->pimg; ?>" width="150px" height="120px"/>





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


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


	


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

[code]

the jquery code

[code]

function readURL(input) {

if (input.files && input.files[0]) {


    var reader = new FileReader();





    reader.onload = function (e) {


        $('#blah').attr('src', e.target.result);


    }





    reader.readAsDataURL(input.files[0]);


}

}

$("#imgInp").change(function(){

readURL(this);

});

[code]

how should i integrate this jquery function in abv form … $form has the htmlOptions

PLEASE HELP! I am new to Yii and am loosing my mind on this. Thank you.

See if the code on this page helps. Note that it uses modern browser features, so I don’t think it’ll work on IE9 and below.

thanx Keith but its not working out … the thing is how do i call a jquery change function using the following … n wt juery is it … :( m a newbei

[code]

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


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


	


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

[code]

You could add an ID to the field:




<?php echo $form->fileField($model, 'pimg', array('id'=>'someId')); ?>



Then use something like




$('#someId').change(...);



yup thanx thanx thanx keith :) it works … :D