3 回答
TA贡献1825条经验 获得超4个赞
经过测试的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贡献1852条经验 获得超7个赞
尝试这个:
<?php
$FileName = '/var/ww/file.txt';
header('Content-disposition: attachment; filename="'.$FileName.'"');
readfile($FileName);
关键是header()。您需要将标题与下载文件一起发送,这将在用户浏览器中强制执行“保存文件”对话框。
- 3 回答
- 0 关注
- 301 浏览
添加回答
举报