Home > php教程 > php手册 > body text

PHP实时统计文件下载次数

WBOY
Release: 2016-06-07 11:37:28
Original
2087 people have browsed it

分享一款文件下载次数统计的代码,主要原理是通过前台点击链接download.php传参id,来更新点击次数。
PHP实时统计文件下载次数
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元

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!