Reputation: 909
In order to hide my images directory, so that the user doesn't know where the images are stored, how can I implement something like this?
<img src="https://photos-1.dropbox.com/t/0/AADkpdIqLbXdAFgmjGbdsKa_InYsOtfwuekNtOyuHgmh3g/10/5642407/jpeg/32x32/6/_/1/2/Pensive%20Parakeet.jpg/HM183nQwcIFtc1PrTIOCRe4rIUK8wBaWKcgqD-g2Ma8?size=32bf&prep_size=1280x960" draggable="true" alt="Pensive Parakeet.jpg" class="sprite sprite_web s_web_page_white_picture_32 icon thumbnail">
renders the image without any problem.
Upvotes: 0
Views: 3898
Reputation: 3826
This type of functionality is typically implemented via a RewriteRule in your vhost or .htaccess file and some sort of image processing function. For example, you can put something like this in an .htaccess file in, say, the /t directory off of your document root:
RewriteEngine on
RewriteCond $1 !^(index\.php|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]
This will transparently redirect all calls behind the scenes to, for example (if placed in your /t directory), /t/0/foo/bar/stuff
to /t/index.php/0/foo/bar/stuff
. Assuming you have an index.php file in that directory, you can then process all of the stuff in the URL it gets by parsing $_SERVER['REQUEST_URI']
or $_SERVER['PATH_INFO']
to figure out exactly what to return.
If you have images saved in an alternate location, you can return them by doing whatever munging you want to do with them and pushing them out to the browser using imagepng()
or imagejpg()
. See the example on one of those pages for how to do this.
Upvotes: 1