开发者

Limiting the file size of users folders

开发者 https://www.devze.com 2023-01-22 07:54 出处:网络
I am developing a file hosting site, where users can upload files to thier own folder. This folder can only have a quota of 100mb. I would like to implement a 开发者_如何学Pythonsytem whereby if a use

I am developing a file hosting site, where users can upload files to thier own folder. This folder can only have a quota of 100mb. I would like to implement a 开发者_如何学Pythonsytem whereby if a user tries tp upload a file to their folder which is already full to 100mb and will exeed their quota, the system will not allow it and display a message to the user.

Any ideas

Thanks

R


Most modern filesystems on most modern operating systems implement some kind of quota support. If you can't use those because to the operating system all the files are owned by just one user then you're going to need to re-implement this functionality.

This means either keeping track of file sizes when they're uploaded, e.g. a row in a database table in which case the question "how much are they already using?" can be answered with one query. Alternatively you could work this out every time someone tries to upload a file, by finding all files they own (presumably from a DB table?) and calling stat() or similar to query the size of each file.

Once you know how much they are already using the POST request or whatever method you're using to do the uploads will tell you the size of the incoming upload.

Be careful with size though - file size is often not the same as size on disk. Which is more important?

0

精彩评论

暂无评论...
验证码 换一张
取 消