How to display image (blob) element stored in database


I am trying to store images in table (field type - blob) & Display the same in a view when requested.

I went through following links in YII WIKI topics:

I think I am able to store the image in database… (A record for which Blob field contains 197670763584419_100000244909867_697429_4864212_n.jpg)…

But i am not able to display the image. (Second wiki link talks about this.)

Please help me find a solution.

My controller:

	public function actionCreate()


		$model=new example;

		// Uncomment the following line if AJAX validation is needed

		// $this->performAjaxValidation($model);













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


			echo $model->file_content;


My _form:

<div class="form">

<?php $form=$this->beginWidget('CActiveForm', array(



	'htmlOptions' => array('enctype' => 'multipart/form-data'),

)); ?>

	<p class="note">Fields with <span class="required">*</span> are required.</p>

	<?php echo $form->errorSummary($model); ?>

	<div class="row">

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

		<?php echo $form->textField($model,'name',array('size'=>60,'maxlength'=>100)); ?>

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



	<div class="row">

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

		<?php echo $form->textArea($model,'profile',array('rows'=>6, 'cols'=>50)); ?>

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



	<div class="row">

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

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

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


	<div class="row buttons">

		<?php echo CHtml::submitButton($model->isNewRecord ? 'Create' : 'Save'); ?>


<?php $this->endWidget(); ?>

</div><!-- form -->

My Model:

public function beforeSave()










		return parent::beforeSave();


public function rules()


		return array(


			array('image', 'file', 'allowEmpty' => false, 'types' => 'jpg, jpeg, gif, png'),




My view:

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

Thank you.


Following code in the View did the trick. Issue solved.

     $dbImage = $this->createUrl('Controller Id/displaySavedImage',array('id'=>$model->primaryKey)); 

     echo CHtml::image($dbImage,'image');

Thank you…

it’s does not work, help!!! i have tried every single post on the forum bat does not work