Page 1 of 1
directory quota
Posted: Sun May 22, 2005 7:37 pm
by hongco
anyone has a good solution on how to limit directory's space. If a user uploads more than a maximum amount, he/she will be denied. Intead of having a file reading total bytes in that directory, is there any other to set it to a max size?
Thanks!
Posted: Sun May 22, 2005 7:52 pm
by Skara
If the user can only upload from a browser, you can simply read the filesize of all the files recursively, easy as can be.
If they have ftp/ssh access, I haven't a clue; I'd like to know too.
Posted: Sun May 22, 2005 7:53 pm
by hongco
i have already mentioned your method

Thanks though. I doublt there is any.
Posted: Sun May 22, 2005 8:18 pm
by Chris Corbyn
Not sure if it works on windows but if you're using *nix then make it a home dir (or subdir of one) for a user with limited quota.
If its not your server then I'd go with your first approach... use a recursive function to check out all the file sizes and give you the total file size.
Something like this but I'm completely blotto cos it's 2:16am and I'm at work soon so need some sleep so someone should check it over first.
Code: Select all
function size_recursive($path, $s=0) {
if (is_dir($path)) {
if ($path != '.' && $path !== '..') {
$h = opendir($path);
while ($f = readdir($h)) {
if (is_dir($path.'/'.$f) && $f != '.' && $f != '..') {
$s = size_recursive($path.'/'.$f, $s);
} else {
$s += filesize($path.'/'.$f);
} //End if
} //End while
closedir($h);
} //End if
} else {
$s += filesize($path);
} //End if
return $s;
} //End function
//Example
$dir = 'c:/webs';
echo size_recursive($dir); //Total size in bytes of c:/webs
Posted: Sun May 22, 2005 8:55 pm
by hongco
thanks d11wtq,
I probably just go with the method you and Skara mentioned, that way the script can be used on any *nix hosting service, and its purpose is to provide members with some web space to upload things to. Thank you for your snippet too.
Here is a cup of coffe to keep your eyes wide open on the road to work:
[_]? <--- capuchino

..on second thought, 2am and going to work, I might let you have a big bowl of coffee - have you ever had one? haha \____/
Posted: Mon May 23, 2005 1:53 am
by timvw
As already mentionned, for EXT2 etc you want to read "man quota".
But if i'm not mistaken, on NTFS you can also apply quotas.. (
http://www.microsoft.com/resources/docu ... o_lvms.asp)