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

$time=time();
mysql_query("INSERT INTO `$mysql[pref]load_k_n` (dir, time, k) values('$dir', '$time', '$k_files')");
mysql_query("DELETE FROM `$mysql[pref]load_k_n` WHERE `time` < '$livetime';");
return $k_files;
}

}
?>
