[英]Different ad on sidebar when user refreshes page or navigates to different page
[英]Start download automatically when a user navigates to another page
我想知道如何實現我在幾個網站上看到的效果,我點擊下載現在鏈接,它帶我到另一個頁面,下載自動開始。 完成此任務的最佳方法是什么?
重定向到發出以下標頭的頁面:
header("Content-Disposition: attachment; filename=$filename");
header("Content-Length: $length");
有關$filename
的限制,請參閱此文章 。
編輯以響應andr的答案,相當於redirect-after-x-seconds的php將是:
header("Refresh: 2; url=start_download.php");
(雖然你應該正式指定一個完整的URL,我認為)start_download.php將包含上面的兩行。
首先,您顯示包含一些內容的頁面(請等待,等等),然后重定向到文件本身或輸出文件的腳本。 重定向通過元標記或javascript完成:
<meta http-equiv="refresh" content="5;url=http://example.com/foo.zip" />
其中«5»是秒 setTimeout("location.href=http://example.com/foo.zip", 5000)
其中«5000»以毫秒為單位。 如果您選擇通過php腳本輸出文件,請按照mvds的回答。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.