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