hi
how can i give a limit for a folder size im my site
Printable View
hi
how can i give a limit for a folder size im my site
It can be done serverside, but if you're the only one uploading, just don't upload more than you want to? I not sure I got your question right.
hi
I added image upload to my site but i want to make the folder at max 10 MB
so how can do it
Quote:
It can be done serverside
Well, in the script that handles uploads, you could calculate the current folder size and check if the addition of the new file will go over the limit. If so, reject the file.
ok
I need php code that do this
can you help me?Quote:
calculate the current folder size and check if the addition of the new file will go over the limit. If so, reject the file.
You could use a recersive function that use the filesize function.
http://www.php.net/manual/en/function.filesize.php
Dimitri over there posted this function:
I haven't tested it but I guess it will work.Code:function dir_size($dir) {
$totalsize=0;
if ($dirstream = @opendir($dir)) {
while (false !== ($filename = readdir($dirstream))) {
if ($filename!="." && $filename!="..")
{
if (is_file($dir."/".$filename))
$totalsize+=filesize($dir."/".$filename);
if (is_dir($dir."/".$filename))
$totalsize+=dir_size($dir."/".$filename);
}
}
}
closedir($dirstream);
return $totalsize;
}