Page 1 of 1
limiting total download size
Posted: Wed Dec 04, 2002 6:04 am
by sploit
i have a user base. and some files on my server. i want to limit a userid to a specific download size in 24 hours.
like a userid = newuser can only download say 1MB from my server every 24 hours; not more than that.
how can i do that using php/mysql? [/b]
Posted: Wed Dec 04, 2002 8:31 am
by f1nutter
Your going to need to track the user so you can keep a record of their downloads. You will need a script that only allows members to access the download area.
Get the file size (
http://www.php.net/manual/en/function.filesize.php) and add it to the users account. If this exceeds there quota over the last 24 hours, do not allow them to download files. Otherwise direct them to the downloadable file.
Table design
Code: Select all
|--------|-------|---------------|
| userid | quota | last_download |
|--------|-------|---------------|
| fred | 500 | 20021204 |
|--------|-------|---------------|
You will need to reset there account if they haven't downloaded anything in the last 24 hours.
Hope this gets you started.
thinking
Posted: Wed Dec 04, 2002 3:45 pm
by AVATAr
thinking a bit...
what happend if the user cancels the download process...??? what do you want to do (f1nutter)?

Posted: Wed Dec 04, 2002 6:07 pm
by volka
I would say "what a pitty". German chess rules have an idiom for that. "berührt, geführt", which means "if touched it has to be moved"

But I would keep track of all download action in the database and let an SQL-statement
sum up all filesizes
in the interval of the last day to now.
And of course a script has to perform the
real download or the user can use the provided link again and again....
Posted: Wed Dec 04, 2002 10:53 pm
by hob_goblin
i would have the table like
userid | quota | total | day
userid would be the user, quote would be the max, total would be the total that they had downloaded that day, and day would be the day.
everytime someone downloaded something the script would first check the day, and if it was a day old, it would reset "total" and "day", next it would see if the size of the request + "total" was > quota, and if it was, then prevent the download. next, if it passed that, it would add "total" plus the request size and update "total" and then download the file.
Posted: Wed Dec 04, 2002 10:56 pm
by volka
so you all prefer a calendar-day-limit, meaning that a user can download it's daily limit from e.g. 23:50 to 23:59 and then again from 0:00 to 0:09 the next day (--> twice the limit in 20 minutes)? Maybe I'm too less generous

Posted: Wed Dec 04, 2002 11:14 pm
by hob_goblin
volka wrote:so you all prefer a calendar-day-limit, meaning that a user can download it's daily limit from e.g. 23:50 to 23:59 and then again from 0:00 to 0:09 the next day (--> twice the limit in 20 minutes)? Maybe I'm too less generous

Yes, but they wouldn't be able to download anything else that day or night.
Posted: Thu Dec 05, 2002 3:01 am
by volka
of course, wouldn't be any limitation otherwise

But I would use a query like
Code: Select all
SELECT SUM(fileSize) FROM member WHERE id=1234 AND tsWhen BETWEEN NOW() AND NOW() - INTERVAL 1 day
to calculate the exact download amount the user has left right at the download moment. Only matter of opinion.
Posted: Thu Dec 05, 2002 8:44 am
by sploit
hey guys, thanks a bundle. this gets me started. the download size limiting policy wasnt as much of an issue as was the mechanism by which to restrict the users

id check out the links given by volka, and get back here when i get stuck!
thanks
