Yii Framework Forum: Display Image - Yii Framework Forum

Jump to content

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

Display Image Image

#1 User is offline   Karthik12 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 38
  • Joined: 15-March 11

Posted 14 June 2011 - 07:36 AM

Hi am new to yii,

Am facing image display problem for the last two days.I can upload image but i cant display that image.How to display image .please help me

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

In Controller.php
  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-length: '.$model->file_size);
    header('Content-Type: '.$model->file_type);
    header('Content-Disposition: attachment; filename='.$model->file_name);

        

but i cant get that image
0

#2 User is offline   rohit 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 71
  • Joined: 08-July 09
  • Location:India

Posted 18 June 2011 - 11:57 PM

in controller, you don't set any header! in view you do set. like following :
View.php --->>
header("Content-type: ".$model->image_type);
echo $model->image_data;


in controller, only first line is enough. which loads data from the db. that's it.
Controller.php--->>actionView()
$this->renderPartial(
  'view',
  array(
    'model'=>$this->loadModel(),
  ),
  false,false
);


and loadModel would be
Controller.php--->loadModel()
public function loadModel()
	{
		if($this->_model===null)
		{
			if(isset($_GET['id']))
				$this->_model=Image::model()->findbyPk($_GET['id']);
			if($this->_model===null)
				throw new CHttpException(404,'The requested page does not exist.');
		}
		return $this->_model;
	}


Try and let me know.
0

#3 User is offline   Karthik12 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 38
  • Joined: 15-March 11

Posted 20 June 2011 - 01:03 AM

View Postrohit, on 18 June 2011 - 11:57 PM, said:

in controller, you don't set any header! in view you do set. like following :
View.php --->>
header("Content-type: ".$model->image_type);
echo $model->image_data;


in controller, only first line is enough. which loads data from the db. that's it.
Controller.php--->>actionView()
$this->renderPartial(
  'view',
  array(
    'model'=>$this->loadModel(),
  ),
  false,false
);


and loadModel would be
Controller.php--->loadModel()
public function loadModel()
	{
		if($this->_model===null)
		{
			if(isset($_GET['id']))
				$this->_model=Image::model()->findbyPk($_GET['id']);
			if($this->_model===null)
				throw new CHttpException(404,'The requested page does not exist.');
		}
		return $this->_model;
	}


Try and let me know.
thanks for giving reply.i got Undefined index:id
0

#4 User is offline   kokomo 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 289
  • Joined: 23-July 10

Posted 20 June 2011 - 02:01 AM

View Postnaga, on 20 June 2011 - 01:03 AM, said:

thanks for giving reply.i got Undefined index:id


There is a similar topic here in the forum with the same problem.

how to display image stored in database

Read it and follow the instructions to debug the error.

@mods maybe it would be good to merge the topics together

This post has been edited by kokomo: 20 June 2011 - 02:03 AM

0

#5 User is offline   Mindphp 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 4
  • Joined: 21-April 11

Posted 26 November 2011 - 11:03 AM

View Postnaga, on 20 June 2011 - 01:03 AM, said:

thanks for giving reply.i got Undefined index:id


id need set form url
sample: index.php?r=c/a/id/10
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