Hello. I am working on a community photo sharing site, and I need some way of controlling the bandwidth. For example I would like to set a maximum bandwidth allowed, which can be image size x the number of times the image was viewed. Similar to what a site like photobucket does (when they replace an image with a bandwidth exceeded image).
I am wondering what the best solution would be. How can I track the number of times an image is viewed? Maybe I need to use something like Google Analytics and then run a cron job every so often to see if any image has exceeded the bandwidth limit? I think this may be overkill and I am over thinking this problem.
By the way, I am developing in PHP.
Any ideas?
Thanks!
UPDATE
Ok, so it seems mod-rewrite is the way to go. Right now I have the following code in .htaccess:
RewriteEngine on
RewriteRule .*.(gif|jpg|jpeg|png)$ /include/image.php
When I go to an actual image (i.e. http://...picture.jpeg), the PHP page image.php loads, but when an image is in an img tag (i.e. img src=http://...picture.jpeg ), the image does not load (good), but the php file does not load in its place.
How do I fix it?
Thanks
SOLUTION
If anyone is interested, this worked (although it can probably be improved):
RewriteEngine on
RewriteRule (.*).(jpg|jpeg|gif|png|wbmp)$ /include/image.php?location=$1&format=$2 [NC,L]
If you look at the $_GET variables image.php is receiving, you can probably figure out what to do from there.