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()

{

    $model=$this->loadModel($_GET['id']);


    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.

Controller.php—>>actionView()




$this->renderPartial(

  'view',

  array(

    'model'=>$this->loadModel(),

  ),

  false,false

);

and loadModel would be

Controller.php—>loadModel()


public function loadModel()

	{

		if($this->_model===null)

		{

			if(isset($_GET['id']))

				$this->_model=Image::model()->findbyPk($_GET['id']);

			if($this->_model===null)

				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