Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

we have a web application written in PHP and we want all our users to be able to upload images for e.g. 50MB.

We will create a directory structure so that every user has its own folder like app/user1/images app/user2/images ...

Now everytime a user uploads an image, we need to check if this is still allowed or not but we don't want 1000 users to continously scan our hard drive counting file sizes in their directory. So writing a script that counts all file sizes in a user directory is not an option I guess?

Is there an easier way to calculate used up space per user and limit our app accordingly?

share|improve this question

2 Answers 2

up vote 3 down vote accepted

Save the size of the uploads in a database table, do a sum (pictures sizes) for the specific user and compare it to their limit when they upload.

Even better to avoid that sum operation you can add the size value of the upload to a column (TotalUploadsSize) in the user table and compare that to the maximum allowed on each upload.

share|improve this answer
    
Storing this data in a database will better enable scaling out without significant application architecture changes as well. –  Warner Mar 26 '10 at 15:13
    
Not to mention the fact that the sky is blue! :) –  Jimmy Mar 26 '10 at 15:39
    
the only problem with this is that we also need to implement subtracting the file size when removing images in several places. –  solsol Jun 29 '10 at 14:12

You could possibly do something with disk quotas on the filesystem.

See the related question about quotas per directory. If you have or can use XFS then you can setup project quotas.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.