当用户浏览到另一个页面时,自动开始下载 [英] Start download automatically when a user navigates to another page
本文介绍了当用户浏览到另一个页面时,自动开始下载的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
解决方案
重定向到发布以下标题的页面:
header(Content-Disposition:attachment; filename = $ filename);
header(Content-Length:$ length);
编辑以回应andr的回答,相当于重定向到x秒的php将是:
header(Refresh:2; url = start_download.php);
(虽然你应该正式指定一个完整的URL,我想)其中start_download.php将包含两个
I was wondering how to accomplish an effect I've seen on several websites, where I click a download now link, it takes me to another page, and the download starts automatically. What is the best way to accomplish this?
解决方案
Redirect to a page which emits the following headers:
header("Content-Disposition: attachment; filename=$filename");
header("Content-Length: $length");
See this post about the restrictions on $filename
.
edit in response to andr's answer, the php equivalent of redirect-after-x-seconds would be:
header("Refresh: 2; url=start_download.php");
(although you should officially specify a complete URL, I think) where start_download.php would contain the two lines above.
这篇关于当用户浏览到另一个页面时,自动开始下载的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文