我想创建一个显示如下消息的 PHP 页面
Your download will begin shortly.
If it does not start, please click here to restart the download
即主要网站上存在的相同类型的页面。
它将像这样工作:
<a href="download.php?file=abc.zip">Click here</a>
当用户单击该链接时,他将被引导至 download.php,该文件向他显示该消息,然后提供文件供下载。
我该怎么做?
非常感谢!
最佳答案
链接需要做以下两件事之一:
- 直接指向您网络服务器上的文件
- 指向一个 PHP 脚本,该脚本只会设置适当的 header 并将文件用作页面主体。没有文字输出!参见 http://teddy.fr/blog/how-serve-big-files-through-php了解如何实际提供文件。
让浏览器“自行”开始下载的一种方法是使用 META REFRESH 标记。
另一种方法是使用 JavaScript,例如这个(来自 Mozilla 的 Firefox 下载页面):
function downloadURL() {
// Only start the download if we're not in IE.
if (download_url.length != 0 && navigator.appVersion.indexOf('MSIE') == -1) {
// 5. automatically start the download of the file at the constructed download.mozilla.org URL
window.location = download_url;
}
}
// If we're in Safari, call via setTimeout() otherwise use onload.
if ( navigator.appVersion.indexOf('Safari') != -1 ) {
window.setTimeout(downloadURL, 2500);
} else {
window.onload = downloadURL;
}
关于php - 如何创建 PHP 'Download will begin shortly' 页面?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3217935/