透明地记录下载的最佳方式? [英] Best way to transparently log downloads?
问题描述
我有一个个人项目已经在线了一段时间。通过这样做,我一直在保持下载次数:
I have a personal project that's been online for sometime now. I've been keeping a tally of downloads by doing this:
- 当用户点击下载链接时,它会点击一个写入的PHP脚本
- 一旦写入数据,脚本将返回到实际文件的路径。
- 然后用户有能力将文件保存到他们的硬盘,就好像是其他的下载一样。
然而,它阻止用户能够右键单击>将目标保存为...
,因为它们实际上只能看到 download.php
出现在文件保存..对话框中。因此,下载项目的唯一方法是左键单击链接。
This has worked well enough for sometime; however, it prevents users from being able to right-click > save target as...
because they'll actually just see download.php
appear in the "File Save.." dialog. Thus, the only way to download the project is to left-click on the link.
我想改进过程,以便用户可以使用他/他最舒服的方法。那么,什么是更好的方式透明地记录下载,而不会进入用户的方式?
I'd like to improve the process so that a user can download the project using whatever method with which s/he is most comfortable. So, what are some better ways to transparently log downloads without getting in the user's way?
对于什么值得,该机器是一个标准的LAMP堆栈,所以没有.NET选项。
For what it's worth, the machine is a standard LAMP stack, so no .NET options here.
推荐答案
这是从 php-documentation ,但也可以使用不同的脚本语言:
This is taken from the php-documentation, but is also possible using different script languages:
<?php
// We'll be outputting a PDF
header('Content-type: application/pdf');
// It will be called downloaded.pdf
header('Content-Disposition: attachment; filename="downloaded.pdf"');
// The PDF source is in original.pdf
readfile('original.pdf');
?>
HTTP头标Content-Disposition会将其保存为下载。
The HTTP-Header Content-Disposition tells it to save it as a download.
另一种选择是定期检查日志文件,比如每天使用脚本。
Another option would be to inspect your log-files regularly, like every day using a script.
这篇关于透明地记录下载的最佳方式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!