limiting total download size

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
sploit
Forum Newbie
Posts: 6
Joined: Wed Dec 04, 2002 6:04 am

limiting total download size

Post 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]
f1nutter
Forum Contributor
Posts: 125
Joined: Wed Jun 05, 2002 12:08 pm
Location: London

Post 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.
User avatar
AVATAr
Forum Regular
Posts: 524
Joined: Tue Jul 16, 2002 4:19 pm
Location: Uruguay -- Montevideo
Contact:

thinking

Post by AVATAr »

thinking a bit...

what happend if the user cancels the download process...??? what do you want to do (f1nutter)?
:wink:
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post 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....
User avatar
hob_goblin
Forum Regular
Posts: 978
Joined: Sun Apr 28, 2002 9:53 pm
Contact:

Post 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.
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post 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 :D
User avatar
hob_goblin
Forum Regular
Posts: 978
Joined: Sun Apr 28, 2002 9:53 pm
Contact:

Post 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 :D
Yes, but they wouldn't be able to download anything else that day or night.
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post 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.
User avatar
sploit
Forum Newbie
Posts: 6
Joined: Wed Dec 04, 2002 6:04 am

Post 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 8O id check out the links given by volka, and get back here when i get stuck!
thanks :!:
Post Reply