PHP:
\n\n(Добавление)<?
// Written by ETC [http://etc2002.narod.ru]
$exfile = "counter.data";
if (!file_exists($exfile)) {
$fp = fopen($exfile,"w");
fclose($fp);
}
if (isset($file)) {
$direcory = ".";
$filename = basename($file);
$directory = dirname($file);
if (strpos($directory,"..")>0) die("Hack attempt...");
if (!is_dir($directory)) die("Directory not found: ".$directory);
if (!file_exists($file)) die("File not found: ".$filename);
} else if (isset($list)) {
echo "<HTML>
<HEAD>
<TITLE>Статистика</TITLE>
<meta http-equiv=\"Content-Type\" content=\"text/html; charset=windows-1251\">
<meta http-equiv=\"pragma\" content=\"no-cache\">
</HEAD>
<BODY BGCOLOR=\"#FFFFFF\">
<H3>Статистика обращений к файлам</H3>\n";
$fp = fopen($exfile,"a+");
$fr = fread($fp,filesize($exfile));
$files = explode("\n",$fr);
while (list($key,$value) = each($files)) {
$cfile = explode(":",$value);
echo "Файл <b>".$cfile[0]."</b> = <font color=\"#ff0000\"><b>".$cfile[1]."</b></font> закачек
\n";
}
echo "</BODY>\n</HTML>";
fclose($fp);
exit;
} else {
die("Bad request");
}
$fp = fopen($exfile,"a+");
$fr = fread($fp,filesize($exfile));
$files = explode("\n",$fr);
$akey = -1;
while (list($key,$value) = each($files)) {
$cfile = explode(":",$value);
$ccfile = $cfile[0];
if ($ccfile==$file) {
$akey = $key;
break;
}
}
if ($akey==-1) {
$fw = fwrite($fp,((filesize($exfile)>0)?"\n":"").$file.":1");
} else {
$count = substr($files[$akey],strpos($files[$akey],":")+1);
$count++;
$files[$akey] = $file.":".$count;
fclose($fp);
$fp = fopen($exfile,"w");
$fw = fwrite($fp,join("\n",$files));
}
fclose($fp);
header ("Location: ".$file);
?>
// Written by ETC [http://etc2002.narod.ru]
$exfile = "counter.data";
if (!file_exists($exfile)) {
$fp = fopen($exfile,"w");
fclose($fp);
}
if (isset($file)) {
$direcory = ".";
$filename = basename($file);
$directory = dirname($file);
if (strpos($directory,"..")>0) die("Hack attempt...");
if (!is_dir($directory)) die("Directory not found: ".$directory);
if (!file_exists($file)) die("File not found: ".$filename);
} else if (isset($list)) {
echo "<HTML>
<HEAD>
<TITLE>Статистика</TITLE>
<meta http-equiv=\"Content-Type\" content=\"text/html; charset=windows-1251\">
<meta http-equiv=\"pragma\" content=\"no-cache\">
</HEAD>
<BODY BGCOLOR=\"#FFFFFF\">
<H3>Статистика обращений к файлам</H3>\n";
$fp = fopen($exfile,"a+");
$fr = fread($fp,filesize($exfile));
$files = explode("\n",$fr);
while (list($key,$value) = each($files)) {
$cfile = explode(":",$value);
echo "Файл <b>".$cfile[0]."</b> = <font color=\"#ff0000\"><b>".$cfile[1]."</b></font> закачек
\n";
}
echo "</BODY>\n</HTML>";
fclose($fp);
exit;
} else {
die("Bad request");
}
$fp = fopen($exfile,"a+");
$fr = fread($fp,filesize($exfile));
$files = explode("\n",$fr);
$akey = -1;
while (list($key,$value) = each($files)) {
$cfile = explode(":",$value);
$ccfile = $cfile[0];
if ($ccfile==$file) {
$akey = $key;
break;
}
}
if ($akey==-1) {
$fw = fwrite($fp,((filesize($exfile)>0)?"\n":"").$file.":1");
} else {
$count = substr($files[$akey],strpos($files[$akey],":")+1);
$count++;
$files[$akey] = $file.":".$count;
fclose($fp);
$fp = fopen($exfile,"w");
$fw = fwrite($fp,join("\n",$files));
}
fclose($fp);
header ("Location: ".$file);
?>
Одно "НО": этот скрипт не выводит показаний типа: "этот файл скачан N раз". Если надо, то могу сделать...