I have uploaded and saved the images in folder and. now i want to view the files. He is what i have done,
$filename = "1.jpg";
$path=Yii::getPathOfAlias('webroot.protected.images') . '/';
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.
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') . '/';
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.
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;
'model' => $this->loadModel($id),
'comment' => $comment,
'imageUrl' => $imageUrl,
in the view script
<h2><?php echo CHtml::encode($model->name); ?></h2>
<?php echo CHtml::image($imageUrl); ?>
<p><?php echo CHtml::encode($comment); ?></p>
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).
Have a look at the source code that’s being generated. What URL is being assigned to the image tag?