Display Image

Hi am new to yii,

     Am facing image display problem for the last two days.I can upload image but i cant display that image.How to display image .please help me

In View.php

<? echo CHtml::link(image,array('displaySavedImage','id'=>$model->primaryKey)); ?>

In Controller.php

  public function actionDisplaySavedImage()



    header('Pragma: public');

    header('Expires: 0');

    header('Cache-Control: must-revalidate, post-check=0, pre-check=0');

    header('Content-Transfer-Encoding: binary');

    header('Content-length: '.$model->file_size);

    header('Content-Type: '.$model->file_type);

    header('Content-Disposition: attachment; filename='.$model->file_name);


but i cant get that image

in controller, you don’t set any header! in view you do set. like following :

View.php —>>

header("Content-type: ".$model->image_type);

echo $model->image_data;

in controller, only first line is enough. which loads data from the db. that’s it.









and loadModel would be


public function loadModel()







				throw new CHttpException(404,'The requested page does not exist.');


		return $this->_model;


Try and let me know.

thanks for giving reply.i got Undefined index:id

There is a similar topic here in the forum with the same problem.

how to display image stored in database

Read it and follow the instructions to debug the error.

@mods maybe it would be good to merge the topics together

id need set form url

sample: index.php?r=c/a/id/10