Page 1 of 1

Setting Maximum Directory Size

Posted: Thu Oct 30, 2003 3:55 pm
by ruthsimon
Is there a function or way to set the maximum size of a subdirectory?

Users are allowed to upload images to a specific subdirectory, but I want to alert when the subdirectory hits a certain size.

Thanks, Ruth

Posted: Thu Oct 30, 2003 4:42 pm
by Gen-ik
Not too sure if that's possible or not, sounds more like a server-setup than a PHP issue.

You could use PHP to add together the sizes of all the files in a directory. If the total size of the files is bigger than X then you can do something from there.

Here's an example..

Code: Select all

<?

$theDir = "myfolder";
$maxSize = "5000"; // size is in bytes.

$d = dir($theDir);
$size = 0;

while(false !== ($file = $d->read()))
{
    if($file != "." && $file != "..") $size = $size + filesize($theDir."/".$file);
    clearstatcache();
}
$d->close();

if($size > $maxSize)
{
    // The directory is full so do something.
}
else
{
    // The directory is no full so do something else.
}

?>