2

I have been trying to figure this out:

I am creating a filehosting site with PHP and I would like to know how to limit user to 10Gb of bandwidth per day, so that they can download - just like RapidShare, until their session is expired. They will be then credited back with 25Gb.

What type of cap can I use to monitor their session of downloading (including resuming) their file?

I know I have to do something with chunk data, or the total chunks completed, and then I can calculate their total chunks.

4
  • This question is too localized and would not be useful to a large amount of other people. It also lacks understanding of punctuation and formatting. Feb 22, 2010 at 4:37
  • i speak french sorry for bad english
    – Saxtor
    Feb 22, 2010 at 4:42
  • This is NOT a PHP question, it is a server question. I think you need to go learn how your server actually works before you start a file hosting service, and you should probably learn how to type while you're at it.
    – animuson
    Feb 22, 2010 at 4:42
  • Exact duplicate of [Bandwidth Monitor ](serverfault.com/questions/153123/bandwidth-monitor)
    – pauska
    Feb 8, 2011 at 14:30

3 Answers 3

0

You could store the users' session IDs in a database along with an amount of data they've downloaded. Each time they download a file, check that their current_usage + size_of_file < 100mb. If it is, allow the download, otherwise present them with an error. Each day reset everyone's current_usage to 0.

2
  • This will be a problem if they pause/resume, as it will be a brand new request, even if they only downloaded 10Mb of a 100Mb file, it will show up as 200Mb consumed Feb 24, 2010 at 4:45
  • its something like this, rapidshare.com/faq5.html i have my code here you can see it and review it for me please check to see how i improve the coding thanks. pastebin.ca/M2c6Cyj8 password ddd
    – Saxtor
    Jun 28, 2010 at 5:03
2

If you want to create a file hosting site which has a limit like this, I'd thing you'll need a specific PHP script to serve the files to download, like incrediman says. If you're not too new to PHP and Web Development, I encourage you to check out this article as well: http://onlamp.com/pub/a/php/2000/09/15/php_mysql.html

In the end the central idea, however, is that end users would always visit the same script (let's say you named it 'download.php') and you'd use something like a query string to dynamically choose what content is served. So to download a filelike 'lenna.jpg' they'd visit a URL similar to "www.yoursite.ex/download.php?file=lenna.jpg ".

Since in doing this, you'll have centralized the downloading in one place/script (this is called the Information Expert Pattern/Principle) you also have a central place to log how much a user has downloaded during their session (PHP has built in support for simplistic session information... see http://php.net/manual/en/features.sessions.php) and a central place to block them once they've downloaded enough.

2
0

Also, you should know that you can use php to initiate a download, which is what you should be doing if you want to be tracking downloads. If you simply link to the file, that won't work. So use the script to initiate the download, and increment their downloaded count that way.

More info on using a script to initiate a download: http://www.ryboe.com/tutorials/php-headers-force-download

2
  • thank you guys i have understand how to create that its creating a counter code of how much downloads per day/user but this is the scary part, if a user was to download the file and to stop it i want to record how much bytes the user used of downloading the file, if the user resume the file i can count how much they left off and deduct it form there traffic balance, i want to understand the amount of chunks sent to the user.
    – Saxtor
    Jun 28, 2010 at 5:01
  • its something like this, rapidshare.com/faq5.html i have my code here you can see it and review it for me please check to see how i improve the coding thanks. pastebin.ca/M2c6Cyj8 password ddd
    – Saxtor
    Jun 28, 2010 at 5:03

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .