2011-04-25 66 views

回答

2

如果任何人都可以在通过键入URL文件得到的,你不能真正指望以任何方式访问除了阅读Web服务器访问日志。

什么你可以做的是:

  1. 让人迹罕至的文件本身通过任何URL
  2. 写一个PHP脚本,“服务档案”根据传递给它
  3. 保留的查询参数从该脚本内计数

通常,步骤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; 
+0

在一个不相关的话题上 - 是否有一个原因,你为什么使用'die'而不是'exit'? – Czechnology 2011-04-25 11:58:57

+1

@科技:没有特别的原因,只是习惯的力量。 – Jon 2011-04-25 12:00:14

+0

好的,谢谢。只有当我想输出某些东西时('die(“Error!”);')和'exit',否则我总是使用'die'。 – Czechnology 2011-04-25 12:07:03

1

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

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

而在这样的文件,你做任何你想要的(日志时间戳,增加下载的数量...)。然后重定向到下载文件。

0

您可以删除直接与.htaccess文件访问文件的能力:

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

如果你不是网络专家。您可以通过将其放入一个文件然后创建该文件来完成@Ale所说的内容。在该文件中,将Google分析结果从此处进行跟踪。你会拥有一切,即使他们在哪里,有多少不同的人......等等。

希望这会有所帮助。

相关问题