Show images form protected folder in frontend

I have some of my images in my protected/images/img folder

In my _view I would like to show them.

I am using the code below


<img class="img" src="<?php echo Yii::app()->getBasePath(); ?>images/img/<?php  echo $data->img;?>



I am not getting any image

How can I show my images?

Hi,

this part of your application is protected by .htaccess, and you can’t simply access it by web browser. You can add to a controller new action that display images and use url to this action as src tag.

You can read more about it here

there are two ways of doing your things :

  1. use CAssetManger publish your protected image file to the public folder, then you have the public path

    which can be used for the img element , <img src='assetUrl ’ …

    if your image folder 's content is often changed ,this is not a good way ;

  2. there is a powerful class library you can use : WideImage (symfony also use it as image library ),it is

    the best GD wrapper class ,you can use it do almost every thing GD can do ; if you use this class

    render you image file (which can be from every where only if you php can access it ) is very easy:




      WideImage::load($yourFilePath)->resize(500, 300)->output('jpg', 90);// only one line  <img src='http://www.yiiframework.com/forum/public/style_emoticons/default/laugh.gif' class='bbc_emoticon' alt=':lol:' /> 

    

you can use this class directly , as an 3rd library just like zend . here is the project address :


[url=&quot;http://wideimage.sourceforge.net/examples/output-to-browser/&quot;]wideimage in sourceforge [/url]  

and there also has a extension in repo :ewideImage

Put your images in an image directory in project root, or in a theme directory.

In short: anywhere else than the protected dir works.

Actually there are rules so some images can only be seen by certain users and also I do not want any body to view those images.

Some images may be seen to users sometimes and sometimes they may see a different image