limiting total download size
Moderator: General Moderators
limiting total download size
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]
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]
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
You will need to reset there account if they haven't downloaded anything in the last 24 hours.
Hope this gets you started.
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 |
|--------|-------|---------------|Hope this gets you started.
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....
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....
- hob_goblin
- Forum Regular
- Posts: 978
- Joined: Sun Apr 28, 2002 9:53 pm
- Contact:
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.
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.
- hob_goblin
- Forum Regular
- Posts: 978
- Joined: Sun Apr 28, 2002 9:53 pm
- Contact:
Yes, but they wouldn't be able to download anything else that day or night.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
of course, wouldn't be any limitation otherwise 
But I would use a query liketo calculate the exact download amount the user has left right at the download moment. Only matter of opinion.
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