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
Setting Maximum Directory Size
Moderator: General Moderators
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..
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.
}
?>