强制下载文件并显示新页面 [英] Force file download AND show a new page
问题描述
我发现了很多示例,这些示例迫使他用PHP下载文件,但是没有一个示例显示如何从新页面执行此操作(例如,感谢您下载页面,如果没有下载该按钮,则带有一个按钮来开始下载)。还没有开始)。每当我使用标头附件方法时,它都会下载文件,同时将浏览器保留在我单击链接时所在的页面上。
I have found numerous examples on forcing he download of a file with PHP, but none of them show how to do this from a new page (e.g. a thank you for downloading page, with a button to start download if it didn't start already). When ever I use the header attachment method it just downloads the file whilst leaving the browser on the page I was on when I click the link.
我希望能够显示一个新页面并自动开始下载。我该如何使用PHP?
I want to be able to show a new page and automatically start the download. How do I do this with PHP?
推荐答案
这可以通过在所需的谢谢页面上进行元刷新来完成。 5
以秒为单位,如果需要,可以将其更改为更长的延迟时间。
It can be done by meta refresh on the "Thank you page" that you want where 5
is in seconds, change it to be a longer delay if you want.
<META HTTP-EQUIV="Refresh" CONTENT="5; URL=/download.php">
然后在您的下载脚本中指向 URL = / download。 php
应该强制下载到需要服务的文件。
Then your download script where you're pointing at URL=/download.php
should do the force download to what ever file it needs to serve.
这篇关于强制下载文件并显示新页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!