3 回答

TA貢獻1818條經驗 獲得超8個贊
經過測試的download.php文件是
function _Download($f_location, $f_name){
$file = uniqid() . '.pdf';
file_put_contents($file,file_get_contents($f_location));
header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
header('Content-Length: ' . filesize($file));
header('Content-Disposition: attachment; filename=' . basename($f_name));
readfile($file);
}
_Download($_GET['file'], "file.pdf");
和下載鏈接是
<a href="download.php?file=http://url/file.pdf"> Descargar </a>

TA貢獻1796條經驗 獲得超7個贊
嘗試這個:
<?php
$FileName = '/var/ww/file.txt';
header('Content-disposition: attachment; filename="'.$FileName.'"');
readfile($FileName);
關鍵是header()。您需要將標題與下載文件一起發送,這將在用戶瀏覽器中強制執行“保存文件”對話框。
- 3 回答
- 0 關注
- 412 瀏覽
添加回答
舉報