本文介紹了如何在 PHP 中自動開始下載?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!
問題描述
需要在 PHP 中添加什么代碼才能在訪問鏈接時自動讓瀏覽器將文件下載到本地機器?
What code do you need to add in PHP to automatically have the browser download a file to the local machine when a link is visited?
我特別想到了類似于下載站點的功能,一旦您單擊軟件名稱,就會提示用戶將文件保存到磁盤?
I am specifically thinking of functionality similar to that of download sites that prompt the user to save a file to disk once you click on the name of the software?
推薦答案
在輸出文件前發送以下標題:
Send the following headers before outputting the file:
header("Content-Disposition: attachment; filename="" . basename($File) . """);
header("Content-Type: application/octet-stream");
header("Content-Length: " . filesize($File));
header("Connection: close");
@grom:關于application/octet-stream"MIME 類型很有趣.我不知道,一直只使用應用程序/強制下載":)
@grom: Interesting about the 'application/octet-stream' MIME type. I wasn't aware of that, have always just used 'application/force-download' :)
這篇關于如何在 PHP 中自動開始下載?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!
【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!