Displaying image From Binary

Hey guys, I have stored an image in the database in binary format like follows.




$model->image=CUploadedFile::getInstance($model,'image');

                          $model->image->saveAs(Yii::app()->basePath . '/' . $model->image);

                          $image = file_get_contents(Yii::app()->basePath . '/' . $model->image);

                          $image = mysql_real_escape_string($image);

                          $sql =  "UPDATE users

                                     set image= '$image'

                                     where users.UserID = $model->UserID" ;

                          Yii::app()->db->createCommand($sql)->execute();

Now my question is how do I display this on a page now. Bear in mind that $model->image is only 1 field in many, there are no other fields that relate to the image however. so $model->image is all I have, no name field or type field. I have tried the following.

Controller




public function actionDisplayImage() {


        $model = users::model()->findByPk((int) $model->UserID);

     

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

            'model' => $model,

        ));

    }



View




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

imagejpeg(imagecreatefromstring(file_get_contents(Yii::app()->basePath . '/' . $model->Signature)));



The view code is just my most recent attemp using other code I have found on the internet, I have tried several different coding methods however All are met with either file or directory doesnt exist or more commonly

"Trying to get property of non-object". Any help on this would be greatly appreciated. Thanks in Advance,

Paul

Dont really understand but, shouldnt be enough this:




public function actionDisplayImage() {


        $model = users::model()->findByPk((int) $model->UserID);

     

        

        if($model){

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

              $model->image;

       }

    }



edit: forgot to mention that you will have to point the source of your IMG element to the action -ie <img src="<?php echo $this->createUrl(‘controller/displayImage’);?>">