On Thursday, October 13, 2011 8:21:44 AM UTC-4, Mirjam wrote:
Hello,
I'm working on a gallery component for which I'm implementing View Access. Now that I've set it up I wondered what to do with users who I don't want to be able to see certain images (e.g. non-registered users who are not allowed to see images in a gallery for registered users), but who are able to download it once they know the image name and where it's stored. E.g. the smart ones who can read the source code, see where images are stored and find out an image file name: they can piece together the direct downloadlink. And I'd like to block them... if possible.
Is it possible to set it up that users knowing the direct link are not
allowed to view/download an image that way, but users with the proper
View Access surfing on the site, can see the galleries that they are
allowed to see in Joomla and are able to download the images?
One method of doing so is to store the files someplace inaccessible to the web server. For an apache web server, you can add an htaccess file as you discovered. You can also store the files outside the web directory entirely, such as if your web directory is /home/username/public_html store the files in /home/username/gallery
When you use this method, it means that to view an image it must be loaded through your component, your component can do a readfile() to load the file and send it to the browser for authorized users.
The downside of this method is that using php to display images is an order of magnitude slower than direct web access. For service static image files, LightHTTP has been shown to process them much much faster. It also has the ability to protect the files with a "secret" dynamic url, see
http://redmine.lighttpd.net/wiki/1/Docs:ModSecDownload for details. Basically, when you generate the image url, you use a shared secret to timestamp the url, and lighty will only allow access to the file if the timestamp matches[this also means that the url constantly changes and old urls cannot be used]
There are also version of this module/functionality for other web servers. For apache:
And for nginx there is something slightly similar:
For a mix of speed and stability, you can use redirects in combination with tokens. So, for example, to view an image the url is:
To break down the url:
gallery - the SEF friendly mapping to your gallery component
album1 - the name of the album
tmpl=component - this parameter tells joomla to use the "component.php" template file instead of the index.php file. This template file just displays the component and no modules, so it is lighter and faster.
If they do not have access rights, then you can use this opportunity to display an error message and cross-sell, such as:
"This image is for subscribers only, please login or subscribe today"
Personally, I'd recommend the redirect method with a secret token. For servers that do not support the generation of tokens, you can code your own solution in PHP using readfile and verify the token.
The benefit of this is threefold:
1) Images have static url's and the redirects help get to the actual image
2) Servers that support token generation get a speed bump
3) Most CDN's also support token secured files, so your app can be extended later to store files in Amazon S3 or a similar service.
This url will call your gallery component