<?
function count_dir_size($dir)
{
global $mysql;
$dir=str_replace("//", "/", $dir);
$livetime=time()-3600;
$q2 = mysql_query("SELECT COUNT(*) FROM `$mysql[pref]load_s` WHERE `time` > '$livetime' AND `dir` = '$dir';");
mysql_query("OPTIMIZE TABLE `$mysql[pref]load_s`;");
if (mysql_result($q2, 0)>0)
{
$q = mysql_query("SELECT s FROM `$mysql[pref]load_s` WHERE `time` > '$livetime' AND `dir` = '$dir' LIMIT 1;");
$size=mysql_fetch_array($q, 1);
return $size['s'];
}
else
{
$size=0;
$od=opendir($dir);
while ($rd=readdir($od))
{
if (is_dir("$dir/$rd") && $rd!='.' && $rd!='..')
{
$size=$size+count_dir_size("$dir/$rd");
}
elseif(!ereg(".name|error.log|.htaccess|.opis|.aut|.jad|.dat|.GIF|.JPG|.PNG",$rd) && $rd!='.' && $rd!='..')
{
$size=$size+filesize("$dir/$rd");
}
}

$time=time();
mysql_query("INSERT INTO `$mysql[pref]load_s` (dir, time, s) values('$dir', '$time', '$size')");
mysql_query("DELETE FROM `$mysql[pref]load_s` WHERE `time` < '$livetime';");
return $size;
}
}
?>
