当用户浏览到另一个页面时,自动开始下载 [英] Start download automatically when a user navigates to another page

查看:103
本文介绍了当用户浏览到另一个页面时,自动开始下载的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道如何完成我在几个网站上看到的效果,我点击下载链接,它需要我到另一个页面,下载开始自动。

解决方案

重定向到发布以下标题的页面:

  header(Content-Disposition:attachment; filename = $ filename); 
header(Content-Length:$ length);

请参阅 $ filename 的限制的-encode-the-filename-of-content-disposition-header-in-content-disposition-header-in-http>这篇文章 p>

编辑以回应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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆