php - 如何创建 PHP 'Download will begin shortly' 页面?

标签 php

我想创建一个显示如下消息的 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,该文件向他显示该消息,然后提供文件供下载。

我该怎么做?

非常感谢!

最佳答案

链接需要做以下两件事之一:

让浏览器“自行”开始下载的一种方法是使用 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/

相关文章:

php - 高级 MySQL 连接。加速查询

javascript - 关于jquery ajax,php文件已运行但成功功能不起作用

javascript - 如何通过倒计时器填充表格单元格

php - 在 PHP 中上传、查看 PDF

php - CodeIgniter 无法在插入函数中获取列名

php - 如何检索laravel5.4存储文件夹中存储的图像?

PHP - 连接/级联多维数组键

php - 从跨浏览器 cookie 中获取值

php - Laravel 中需要等效(不存在)whereHour 命令

php - 分页变量和其他变量在php中有冲突