php - 启动下载的最佳方式?

标签 php javascript download

在基于 PHP 的网站上,我想在用户填写简短表格后向他们发送下载包。网站启动的下载应该类似于 download.com 等网站,上面写着“您的下载将立即开始。”

我知道的一些可能的方法,以及浏览器兼容性(基于快速测试):

1) window.open 指向新文件。

- FireFox 3 blocks this.  
 - IE6 blocks this.  
 - IE7 blocks this.

2) 创建一个指向新文件的 iframe。

- FireFox 3 seems to think this is OK. (Maybe it's because I already accepted it once?)  
 - IE6 blocks this.  
 - IE7 blocks this.

How can I do this so that at least these three browsers will not object? 

奖励:是否有不需要浏览器条件语句的方法?

(我相信 download.com 有条件地采用了这两种方法,但我无法使任何一种起作用。)

回应和澄清:

Q: "Why not point the current window to the file?"  
A: That might work, but in this particular case, I want to show them some other content while their download starts - for example, "would you like to donate to this project?"

更新:我已经放弃了这种方法。原因请看下面我的回答。

最佳答案

您还可以进行元刷新,大多数浏览器都支持。 Download.com 在 noscript 标签中放置了一个。

<meta http-equiv="refresh" content="5;url=/download.php?doc=123.zip"/>

关于php - 启动下载的最佳方式?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60590/

相关文章:

javascript - 如何创建两个选择列表并且只允许一项选择?

javascript - 获取 : I see the response in the DevTools but Fetch still gives me an "Access-Control-Allow-Origin" issue for GET

c# - 从 ASP.NET Web 处理程序 (.ashx) 下载文件时的错误处理

audio - 在Drupal的同一页面上播放和下载音频文件

php - mysql在开头加值(concat),不在结尾?

php - ftp_rawlist 在 ProFTPd 服务器上返回 false

php - array_merge 没有按预期工作

javascript - Mongodb $inc 返回双倍

javascript - Twitter API 1.1 从 PHP 获取 json 以在 Javascript 中使用

Github 下载文件夹为 zip