xuexixuexi2
V2EX  ›  问与答

用 Apache 做下载站问题求助

  •  
  •   xuexixuexi2 · Dec 29, 2015 · 2451 views
    This topic created in 3821 days ago, the information mentioned may be changed or developed.

    我现在有台 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 配置中,肯定可以解决的
    请大家指点。

    No Comments Yet
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   870 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 29ms · UTC 22:01 · PVG 06:01 · LAX 15:01 · JFK 18:01
    ♥ Do have faith in what you're doing.