PHP实时统计文件下载次数
程序员文章站
2022-06-14 12:42:44
...
分享一款文件下载次数统计的代码,主要原理是通过前台点击链接download.php传参id,来更新点击次数。
download.php
download.php
$id = (int) $_GET['id'];
if (!isset($id) || $id == 0)
die('参数错误!');
$query = mysql_query("select * from downloads where id='$id'");
$row = mysql_fetch_array($query);
if (!$row)
exit;
$filename = iconv('UTF-8', 'GBK', $row['filename']); //中文名称注意转换编码
$savename = $row['savename']; //实际在服务器上的保存名称
$myfile = 'files/' . $savename; //文件
if (file_exists($myfile)) {
mysql_query("update downloads set downloads=downloads+1 where id='$id'");
$file = @ fopen($myfile, "r");
header("Content-type: application/octet-stream");
header("Content-Disposition: attachment; filename=" . $filename);
while (!feof($file)) {
echo fread($file, 50000);
}
fclose($file);
exit;
} else {
echo '文件不存在!';
}
PHP统计下载次数演示:http://www.sucaihuo.com/php/224.html PHP+Mysql+jQuery统计文件下载次数.zip ( 5.96 KB 下载:47 次 )
AD:真正免费,域名+虚机+企业邮箱=0元