Web Hosting Talk







View Full Version : Image/File hosting script and bandwidth question


OneBinary
04-07-2006, 07:20 PM
Hello All,

I plan on starting to develop a free file/image hosting website, and I had a question. Please note I have not started coding the script, I've just started thinking about it at the abstract level.

How would I go about keeping track of how much bandwidth each user has consumed? Would I have to analyze the access logs on a scheduled basis, like every hour? I dunno, I've been thinking about it for the past few days and I'm at a loss.

Any help would be greatly appreciated.

orbitz
04-07-2006, 07:46 PM
every image should have its its size recorded to a database. To access an image, use a file and have the link something like this: yoursite/display.php?img=myimage.jpg ... the file display.php will keep a record of times the image get accessed. This would give you the bandwidth taken up by someone accessing the image.

Burhan
04-08-2006, 01:31 AM
I'm not sure how effective this will be, but there is a mod_bandwidth module for Apache that you might want to investigate.

Spyro
04-08-2006, 02:02 AM
Have your users access the file through the script (hide the actual path, so that they don't directly download). Keep the file size in the database. Keep the number of times it has been accessed that month in the database. Have your script look at said values and determine how much bandwidth has been confused.

Alternatively, you could write a script that analysis apache log files every hour or so and figures out bandwidth from that. This has the added benefit of being able to give users ftp access, but if that is not what you are looking for, doing it by script would be the preferable method. Admittedly, there are probably some more inventive ways of going about things but this is food for thought and not really a solution.

orbitz
04-08-2006, 10:16 AM
well, only allow the php file access to image folder will prevent others from accessing the image file directly. Besides, it will be able to control bandwidth per users if you ever need to setup user account.

I am not sure if mod band_width can track bandwidth per user account.

OneBinary
04-08-2006, 01:51 PM
Awesome, thank you all for your suggestions. I think a download.php type of file is the way to go.

Thanks again

wolseley
04-08-2006, 02:52 PM
We use a php script to serve the files. We use a MySQL database which keeps track of file sizes and bandwidth usage.

Two important points of advice for you:

1. Some sites will not let you use a .php file as am image. i.e. myspace will not let your users use images on your site if the link is: http://www.mydomain.com/image.php?filenum=XXXXX or similar. You can get round this by using mod_rewrite so that the urls look like real images.

2. Think about how your script handles requests from clients who already have a cached version of the image. You will need to analyse the apache header info to see if they are requesting to see if the image has been modified, and serve the image appropriately (i.e. return the correct not modified header or just reserve the image). You then need to decide how you handle the users bandwidth usage if you have not had to serve the whole image again.

Czaries
04-29-2006, 01:40 AM
I was about to say just what wolseley just said: use mod_rewrite instead of 'download.php?file=xxxxx'

Do something like:

/get/xxxxx [mod_rewrite =>] download.php?file=xxxxx