用 Apache 做下载站问题求助

2015-12-29 03:56:37 +08:00
 xuexixuexi2

我现在有台 Windows 服务器,安装了 wamp 做站, php 5.1.1 ,这些都是现成的,没法修改了,我现在想加个下载站,我想要统计用户的下载量,以及是否成功下载

代码我把它简化了,大体上是:
<?php
$filename = "test.exe"; // 要下载的文件名
// 开始下载,记录到数据库中, flag 是 0
$dbconn = mysql_connect("localhost", "root", "");
mysql_select_db("download", $dbconn);
$dbresult = mysql_query("INSERT INTO tbl_downloads(filename, flag) VALUES("'" . $filename . "', 0");", $dbconn);
mysql_close($dbconn);
$filepath = "C:/wamp/www/" . $filename;
// 发送文件给用户
@header('Content-type: application/octet-stream');
@header('Content-Disposition: attachment; filename=' . $filename);
@header('Accept-Ranges: bytes');
@header('Content-Length: ' . filesize($filepath));
@header('Cache-control: no-cache,no-store,must-revalidate');
@header('Pragma: no-cache');
@header('Expires: 0');
$file = @fopen($filepath, "rb");
@fpassthru($file);
@fclose($file);
// 下载完成,记录到数据库中, flag 是 1
$dbconn = mysql_connect("localhost", "root", "");
mysql_select_db("download", $dbconn);
$dbresult = mysql_query("INSERT INTO tbl_downloads(filename, flag) VALUES("'" . $filename . "', 1");", $dbconn);
mysql_close($dbconn);
?>
现在遇到的问题是,下载完成的代码不执行了,也就是 flag 为 1 的记录没有保存到数据库中!请问哪里出了问题?
先声明:第一,这个代码在我其它 linux 的下载站上是可以工作的,下载完成后是会记录到数据库中的
第二,我看了 apache 的 log 和 php 的 log ,这里根本没发生错误
第三,换操作系统,服务器, php 这些都不现实,而且我相信问题要么出在 php 代码中,要么出在 apache 配置中,肯定可以解决的
请大家指点。

1651 次点击
所在节点    问与答
0 条回复

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/246818

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX