[SOLVED] How to display Protected Images?

Hi R.K. can you please post your solution? I too want to serve images below root…

Hi ,

Doesn’t below simply solve the problem with accessing files outside webroot?

$url = Yii::app()->assetManager->publish(’/any/path/to/image.jpg’);

The problem wasn’t that an image didn’t happen to be under the webroot directory; the problem was keeping the image private. If you use “publish” then the image would end up in the assets directory which is publicly visible. Granted, the assets subdirectories are difficult to guess, but a user can always look at the specific assets directory that was used to download their files and end up seeing other people’s files.

If you want to be really secure about ONLY showing an image to a specific, authorized user, then the ‘readfile’ solution is best. I used this solution on my website which lets a group share images with other group members, but no one else can see them.