Earlier, I posted directions for getting it to work with attachments as files. I've updated the function so it's a little nicer and handles errors better. Now if you have the dir path set wrong, safe mode is on, or you don't have permission for some reason, you'll get "NA" instead of a nasty looking error. Plus It now tells you how many files there are instead of just total file size. I use this to read server dirs, custom avs as files, attachments as files, profile pics, and sig pics. If you already installed this before, just replace the old dizsize function with this one
UPDATED : modified it to work with attachments af files
replace this
PHP Code:
$attach = $DB_site->query_first("SELECT SUM(LENGTH(filedata)) AS size FROM attachment");
with this
PHP Code:
function dirsize($path) {
$totalsize = 0;
$totalcount = 0;
if ($handle = @opendir($path)) {
while (false !== ($file = readdir($handle))) {
$nextpath = $path . '/' . $file;
if ($file != '.' && $file != '..' && !is_link ($nextpath)) {
if (is_dir ($nextpath)) {
$result = dirsize($nextpath);
$totalsize += $result[size];
$totalcount += $result[count];
} elseif (is_file ($nextpath)) {
$totalsize += filesize ($nextpath);
$totalcount++;
}
}
}
closedir ($handle);
$totalsize = sprintf('%.2f',$totalsize/1048576);
$mgs_size = $totalcount.' files : '.$totalsize.' MB';
} else {
$mgs_size = "<em><font color=#FF0000>NA</font></em>";
}
return $mgs_size;
}
then replace this
PHP Code:
makelabelcode('Attachment Usage:', kbtomb($attach['size']));
with this
PHP Code:
makelabelcode('Attachment Usage:', dirsize($attachpath));