如何判断一个文件真的下载并保存,尽管浏览器prefetch /缓存? [英] How to tell if a file was really downloaded and saved, despite browser prefetch/cache?

查看:236
本文介绍了如何判断一个文件真的下载并保存,尽管浏览器prefetch /缓存?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建一个脚本,以保持下载统计,但我只想更新​​统计数据,如果该文件是实际下载。

I am creating a script to keep download statistics, but I would only like to update the stats if the file was ACTUALLY downloaded.

问题是,浏览器(例如,资源管理器9,Chrome浏览器...)自动开始下载文件,而保存/打开对话框仍处于打开状态。这意味着该文件可以完全下载(到浏览器中指定的临时目录我假设)用户指定的保存位置之前(或在资源管理器中仍显示黄色警告条)。

The problem is that browsers (e.g., Explorer 9, Chrome, ...) automatically start downloading the file while the 'save/open' dialog is still open. This means the file can completely download (into a browser specified temp directory I assume) before the user has specified where to save it (or while Explorer still shows the Yellow warning bar).

用户可以决定取消保存,即使文件被成功下载。我怎么能告诉浏览器不自动开始下载?一些HTTP头吧?
任何其他解决办法?

The user may decide to cancel the save, even though the file was successfully downloaded. How can I tell browsers not to automatically start downloading? Some HTTP header perhaps? Any other solutions?

推荐答案

您不能做你想要做的事。这是不可能的,至少在你所问的方式。

You can't do what you are wanting to do. It is impossible, at least in the way you are asking.

您的能有什么的做的就是把一些code。在伸手到您的服务器时,它运行时,你的脚本可以跟踪它,然后安装程序。这是常见,但肯定的不可以万无一失。许多人下载软件并安装离线。 (特别是拨号用户,这是仍然在那里的数千人。)此外,也不能保证安装程序不会被防火墙软件或一些被封锁。

What you can do is put some code in the installer that reaches out to your server when it runs, and your script can keep track of it then. This is commonly done, but is certainly not foolproof. Many people download software and install offline. (Particularly, dial-up users, which are still out there by the thousands.) Also, there is no guarantee that the installer won't be blocked by firewall software or something.

因此​​,这一切都取决于你需要多么糟糕知道是安装时。如果它是至关重要的,那么你的安装程序需要在安装前与服务器进行验证。当然,这可以被砍死左右,并没有什么可以做的。但是,我怀疑它会满足您的需要。

So this all depends on how bad you need to know when it was installed. If it is critical, then your installer needs to verify with the server before installing. Of course this can be hacked around, and there is nothing you can do about it. But, I suspect it will work for your purposes.

另外,不要忘了每次下载多个安装。

Also, don't forget about multiple installs per download.

这篇关于如何判断一个文件真的下载并保存,尽管浏览器prefetch /缓存?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆