Update And Preview File

I have a blob field in my database table where I’m supposed to save a jpg, jpeg image and this is rule in the model:


[	array('Odtis', 'file',

						'types'=>'jpg, jpeg',

						'maxSize'=>1024 * 1024 * 10, // 10MB

						'tooLarge'=>'The file was larger than 10MB. Please upload a smaller file.',

						'allowEmpty' => true

				),

Now I’ve uploaded and saved the image sucessfully. I have a problem with updating my object because the value that is in blob field does not save in the next object if I click on update. Here is my update function:


public function actionUpdate($id)

	{

		$model=$this->loadModel($id);

		

		// Uncomment the following line if AJAX validation is needed

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


		if(isset($_POST['Zigi']))

		{

			$model= new Zigi();

			$model->attributes=$_POST['Zigi'];

			if($model->save())

				$this->redirect(array('view','id'=>$model->idzigi));

		}


		$this->render('update',array(

			'model'=>$model,

		));

	}

I needed to slightly update the function because i want that every change in object can be seen and tracked. So I get multiple rows in database for a single object and I can review all changes that has been made. But the problem is that this way I do not get the blob field populated in the new object. How can I do that?

The second question I have is how can I show a preview of picture I have in blob field and not just have a link to that picture in

CGridView:


		array(

			'class'=>'CLinkColumn',

			'header'=>'Odtis',

			'labelExpression'=>'(!empty($data->Odtis))?$data->ImeDatoteke:""',

			'urlExpression'=>'(!empty($data->Odtis))?array("displaySavedImage","id"=>$data->idzigi):""',

		),		

and

CDetailView:


		array(

			'type'=>'raw',

	   		'name'=>'Odtis',

			'value'=>CHtml::link($model->ImeDatoteke,array('displaySavedImage','id'=>$model->idzigi)),

   			'htmlOptions'=>array('width'=>'50')

		),

displaySavedImage function:


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-Type: image/jpg');

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

	

		echo $model->Odtis;

	}

Are there any simple ways to do that?

hi @Rasho I recommend you to dont save image in database instead save the image into file system and theb save the image info to the database.