如何计算文件请求

时间:2011-04-25 11:36:02

标签: php file redirect ftp download

就像,我在ftp http://site.com/download/file.zip

上有文件

我直接从浏览器的地址标签请求下载。

如何计算此文件的请求数?

或者如何删除此类请求的能力,因此它们应该只能通过php工作?

4 个答案:

答案 0 :(得分:2)

如果有人可以通过输入URL来获取文件,除了阅读Web服务器访问日志之外,您无法以任何方式真正计算访问次数。

可以做的是:

  1. 通过任何网址
  2. 使文件本身无法访问
  3. 根据传递给它的查询参数编写一个“提供文件”的PHP脚本
  4. 从此脚本中保留计数
  5. 通常,步骤2中的脚本看起来有点像这样:

    // Increase your "download count" by one
    
    // $mimeType is the MIME type of the file you are serving
    //     e.g. "application/octet-stream"
    // $filename is the name that the browser will offer as a default
    //     in the "save file" dialog
    // $filepath is the real path of the file on your web server
    
    header('Content-Type: '.$mimeType);
    header('Content-Disposition: attachment; filename="'.$filename. '";' );
    header('Content-Length: '.filesize($filepath));
    
    readfile($filepath);
    die;
    

答案 1 :(得分:1)

您可以创建一个处理下载的download.php文件。我的意思是:

http://site.com/download.php?dl=file

在这样的文件中,你可以做任何你想做的事情(记录时间戳,增加下载次数......)。然后重定向以下载文件。

答案 2 :(得分:0)

您可以删除使用.htaccess文件直接访问文件的功能:

<FilesMatch ~ "^file\.zip$">
    Deny from all
</FilesMatch>

答案 3 :(得分:0)

如果您不是网络大师。您可以通过将其放入文件然后创建文件来执行@Ale所说的操作。在该文件中,放置Google分析并从那里跟踪它。你将拥有一切,即使它们在哪里,有多少不同的人......等等。

希望这有帮助。

相关问题