Yii Framework Forum: Error Displaying The Saved Image ......... - Yii Framework Forum

Jump to content

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

Error Displaying The Saved Image ......... Rate Topic: -----

#1 User is offline   rajkumar000000 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 88
  • Joined: 18-September 12

Posted 11 November 2012 - 03:20 AM

I have uploaded and saved the images in folder and. now i want to view the files. He is what i have done,



in controller:

$productindex=$this->loadModel($id);
$comment=$this->createComment($productindex);
$filename = "1.jpg";
$path=Yii::getPathOfAlias('webroot.protected.images') . '/';
$file=$path.$filename;
if (file_exists($file))
{
$this->render('view',array(
'model'=>$this->loadModel($id),
'mblspecificationDataProvider'=>$mblspecificationDataProvider,
'comment'=>$comment,
'filepath'=>$file,
));
}
}



in view file:
echo CHtml::image(filepath, 'productimage', array('class' => 'productindex'));

but i getting error - undefined constant assumed filepath.

i put the filepath in quotes and then error goes off but i see just the alternative text i.e productimage.

please suggest how to view file which i have stored in folder.
0

#2 User is offline   softark 

  • Keep It Simple
  • Yii
  • Group: Moderators
  • Posts: 2,083
  • Joined: 16-February 11
  • Location:Japan

Posted 11 November 2012 - 03:50 AM

You've forgotten the $ mark. :)
echo CHtml::image($filepath, 'productimage', array('class' => 'productindex'));

And you should store your images under web root folder, not in the application folder.
0

#3 User is offline   rajkumar000000 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 88
  • Joined: 18-September 12

Posted 15 November 2012 - 04:49 AM

View Postsoftark, on 11 November 2012 - 03:50 AM, said:

You've forgotten the $ mark. :)
echo CHtml::image($filepath, 'productimage', array('class' => 'productindex'));

And you should store your images under web root folder, not in the application folder.




thanks a lot softark..
i had done this thing after that error become solve but image is not display.
again i have change some code i.e,

$filename = '1.jpg';
$path=Yii::getPathOfAlias('webroot.images') . '/';
$file=$path.$filename;

if (file_exists($file))
{
ob_clean();
header('Content-Type: image/jpeg');
readfile($file);
exit;


$this->render('view',array(
'model'=>$this->loadModel($id),
'mblspecificationDataProvider'=>$mblspecificationDataProvider,
'comment'=>$comment,
'filepath'=>$file,
));
}

after that i show image is display in whole page and details of product is not display.where is the problem i am not able to identified to show both the thing (image and details of the project).
here i choose only one image for displaying.how to select web folder in place of "1.jpg".
Any help is most appreciated.
Thanks!
0

#4 User is offline   softark 

  • Keep It Simple
  • Yii
  • Group: Moderators
  • Posts: 2,083
  • Joined: 16-February 11
  • Location:Japan

Posted 15 November 2012 - 07:36 AM

Usually we do something like the following to display an image with the text contents.

in the controller
...
$filename = 'some-image.jpg';
$imageUrl = Yii::app()->homeUrl . 'images' . DIRECTORY_SEPERATOR . $filename;
$this->render('view',array(
   'model' => $this->loadModel($id),
   'comment' => $comment,
   'imageUrl' => $imageUrl,
));
...


in the view script
...
<div>
<h2><?php echo CHtml::encode($model->name); ?></h2>
<?php echo CHtml::image($imageUrl); ?>
<p><?php echo CHtml::encode($comment); ?></p>
</div>
...


URL You have to use the URL when you want the user's browser to access some resource in the server. For example, "http://your.domain.com/images/some-image.jpg". This is for your user.

PATH You have to use the PATH when you want to access some resource in the server for yourself. For example, "/var/www/html/images/some-image.jpg". This is for yourself.
1

#5 User is offline   rajkumar000000 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 88
  • Joined: 18-September 12

Posted 15 November 2012 - 08:50 AM

View Postsoftark, on 15 November 2012 - 07:36 AM, said:

Usually we do something like the following to display an image with the text contents.

in the controller
...
$filename = 'some-image.jpg';
$imageUrl = Yii::app()->homeUrl . 'images' . DIRECTORY_SEPERATOR . $filename;
$this->render('view',array(
   'model' => $this->loadModel($id),
   'comment' => $comment,
   'imageUrl' => $imageUrl,
));
...


in the view script
...
<div>
<h2><?php echo CHtml::encode($model->name); ?></h2>
<?php echo CHtml::image($imageUrl); ?>
<p><?php echo CHtml::encode($comment); ?></p>
</div>
...


URL You have to use the URL when you want the user's browser to access some resource in the server. For example, "http://your.domain.com/images/some-image.jpg". This is for your user.

PATH You have to use the PATH when you want to access some resource in the server for yourself. For example, "/var/www/html/images/some-image.jpg". This is for yourself.




thanks for the quick reply...

i had done all the thing as u suggest me after that i have found that details of the product and name of the image display but not show the image.
my image is store at web folder(c:xampp/htdocs/projectname/images).
0

#6 User is online   Keith 

  • Elite Member
  • Yii
  • Group: Moderators
  • Posts: 1,630
  • Joined: 04-March 10
  • Location:UK

Posted 15 November 2012 - 09:28 AM

Have a look at the source code that's being generated. What URL is being assigned to the image tag?
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