Yii Framework Forum: Display Image from database blob type - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Display Image from database blob type Rate Topic: -----

#1 User is offline   PK95 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 13
  • Joined: 02-February 17

Posted 10 July 2018 - 03:38 AM

the image is showed, but its not full image. just half from it.

in view
$dbImage = Yii::app()->createUrl('photo/displaySavedImage', array('id' => my_id));
    echo CHtml::image($dbImage, 'image', array('width' => 200, 'height' => 200));


Model
    public function rules() {
            array('image', 'file', 'types' => 'jpg, png, gif'),
        );
    }


    public function beforeSave() {
        if ($file = CUploadedFile::getInstance($this, 'image')) {
            $this->imagename = $file->name;
            $this->imagetype = $file->type;
            $this->imagesize = $file->size;
            $this->image = file_get_contents($file->tempName);
        }
        return parent::beforeSave();
    }


Controller

    public function actionDisplaySavedImage() {
        
        $model = $this->loadModel($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-length: '.$model->imagesize);
	header('Content-Type: '.$model->imagetype);
	header('Content-Disposition: attachment; filename='.$model->imagename);

        echo $model->image;
    }


nothing wrong when saving the image.
but when display the image, it just display half of it like the image i uploaded.

please help me solved this question.
0

#2 User is offline   PK95 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 13
  • Joined: 02-February 17

Posted 10 July 2018 - 03:41 AM

this is the image i've mentioned

Attached File(s)


0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users