Part of the EllisLab Network
   
 
Upload data
Posted: 06 May 2007 04:40 AM   [ Ignore ]  
Summer Student
Total Posts:  14
Joined  03-15-2007

I am curently working on a file-sharing application which allows regsitered users to upload files onto the server.
Information about the files are stored in a database.

The problem I am having is stopping a file from being uploaded if the user has reached their upload limit. The users table in the database contains a set amount of space for each user. How can I ensure that they canot upload a file if they will go over their limit?

I would even be happy if someone could show me how I could simply delete the file after upload if the limit is reached.

Thanks for the help.

Profile
 
 
Posted: 06 May 2007 05:13 AM   [ Ignore ]   [ # 1 ]  
Lab Assistant
Avatar
RankRank
Total Posts:  248
Joined  02-10-2007

In your users table, you could create a field called used_diskspace. Every time a user loads up a file, you add the filesize to that field. Every time a user deletes one of his files, you substract it from that field.

So, when a user uploads a new file, you take the size of that file and check whether he has still enough diskspace left. If not, show an error, else continue the upload.

Makes sense?

 Signature 

Kohana rocks!

Profile
 
 
Posted: 06 May 2007 07:01 AM   [ Ignore ]   [ # 2 ]  
Research Assistant
Avatar
RankRankRank
Total Posts:  352
Joined  04-27-2006
Game Makker - 06 May 2007 04:40 AM

I would even be happy if someone could show me how I could simply delete the file after upload if the limit is reached.

hm, if I remember correctly, if you don´t call the php function move_uploaded_file() then the file will remain in the tmp folder and will be deleted automacially…
so just don´t call the CI upload library or move_uploaded_file() and it should be enough…

Profile
 
 
Posted: 06 May 2007 09:50 AM   [ Ignore ]   [ # 3 ]  
Summer Student
Total Posts:  14
Joined  03-15-2007
Geert De Deckere - 06 May 2007 05:13 AM

In your users table, you could create a field called used_diskspace. Every time a user loads up a file, you add the filesize to that field. Every time a user deletes one of his files, you substract it from that field.

So, when a user uploads a new file, you take the size of that file and check whether he has still enough diskspace left. If not, show an error, else continue the upload.

Makes sense?

Yeah that’s what I am doing I was just wandering if there was anything in CI that would let me cancel an upload but obviously not. Thanks for the info.

Profile
 
 
Posted: 06 May 2007 10:32 AM   [ Ignore ]   [ # 4 ]  
Lab Assistant
Avatar
RankRank
Total Posts:  248
Joined  02-10-2007
gunter - 06 May 2007 07:01 AM

hm, if I remember correctly, if you don´t call the php function move_uploaded_file() then the file will remain in the tmp folder and will be deleted automacially…

You’re right. The file will be deleted from the temporary directory at the end of the request if it has not been moved away or renamed.

More info @ http://php.net/manual/en/features.file-upload.php

 Signature 

Kohana rocks!

Profile
 
 
   
 
 
Post Marker Legend
New Topic New posts Hot Topic Hot Topic with new posts New Poll New Poll Moved Topic Moved Topic Sticky Topic Sticky topic
Old Topic No new posts Hot Old Topic Hot Topic with no new posts Old Poll Old Poll Closed Topic Closed Topic Announcement Announcements
Theme
Change Theme
Visitor Statistics
The most visitors ever was 719, on June 06, 2008 10:16 AM
Total Registered Members: 64452 Total Logged-in Users: 21
Total Topics: 80957 Total Anonymous Users: 0
Total Replies: 435678 Total Guests: 173
Total Posts: 516635    
Members ( View Memberlist )