I have some problems with display an images. Images stored in database.
i have method of model-class
public function imageShow()
and i use it in views like this:
<?php echo CHtml::image($model->imageShow()); ?>
but my browser give me something like this: Image couldn’t display because of has an error. This error just when i sending a header
, but without content-type display just binary data of image.
Does anyone know how to display images from database?
I’m sure this won’t work, because CHtml::image() takes the image url as the first parameter but your imageShow() method returns nothing, just sends the binary data to the output.
You should create an action that sends the image and point to that action in CHtml::image() methods first parameter.
So something like this:
class MyImageController extends CController
public function actionDisplayImg()
$model = $this->loadModel();
Yii::app()->request->sendFile('myimage.png', $model->image, 'image/png');
<?php CHtml::image($this->createUrl('myImage/displayImg')); ?>
Ooo, it’s nice decision. Thank you very much. Your post help me a lot.
It does not show image, help!!!! i have tries every post bau i can not display a image save tro database
why store images in database?
it make ur app to have a very lower performance, instead save images name and address in db