Displaying Image from DB

I have been trying from last three days to display image from Database. But all attempts have proved futile. I have used the ideas of zaccaria, Ramirez, Rohit, but all in vain. The images in the disk can be displayed without any problem by just specifying the path. The images in databases can be displayed by plain php script. But somehow, Yii and blob in db don’t work. The common errors are - ‘You are not authorised …’, ‘Server is not able to request…’, only url getting displayed etc. etc.

Can an expert give the full code for controller and view separately as an example. Maybe I am dumb, but half codes especially for view is driving me nuts!

may be you should post your code so we can look at it and pinpoint where the issue is.

Thanks, I will post the code here. It is derived from zaccaria

The controller code is:

public function actionDisplaySavedImage()




 	header('Content-type: image/jpg');

 	echo $model->logoContent;




The view code is (I have hard coded the id for simplification):

<div class="view">

<? echo CHtml::link(Yii::app()->request->url,array('displaySavedImage','id'=>'1')); ?>


Do you have ‘displaySavedImage’ in your controller accessRules?

Also, what error do you have with your code? Can you copy-paste it?

Third Edit:

I also believe you should have [color="#FF0000"]$id[/color] here:

public function actionDisplaySavedImage($id)

since you attempt to pass $id as an argument.

Try it and tell me.

The error is here:<br><br>

[font="Helvetica, Arial, sans-serif"][size="2"]The website encountered an error while retrieving http://localhost/con...laySavedImage/1. It may be down for maintenance or configured incorrectly.[/size][/font][font="Helvetica, Arial, sans-serif"][size="2"]

Here are some suggestions:

  • Reload this webpage later.

[/size][/font][color="#777777"][font="Helvetica, Arial, sans-serif"][size="2"]HTTP Error 500 (Internal Server Error): An unexpected condition was encountered while the server was attempting to fulfill the request.<br><br>[/size][/font][/color]

And it happens in all browsers. But with plain php script, the image is displayed.