如何在PHP中强制下载?

时间:2015-01-26 06:51:38

标签: php force-download

如何强制下载多个链接?如果用户单击link1,则下载pdf1.pdf。如果用户单击link2,则下载pdf2.pdf。有没有办法检查他们点击了哪个链接?

2 个答案:

答案 0 :(得分:3)

尝试

<?php
$FileName = 'file.pdf';
header('Content-disposition: attachment; filename="'.$FileName.'"');
readfile($FileName);

答案 1 :(得分:0)

$file_url = 'your_file.someting';
header('Content-Type: application/octet-stream');
header("Content-Transfer-Encoding: Binary"); 
header("Content-disposition: attachment; filename=\"" . basename($file_url) . "\""); 
readfile($file_url);

P.S。为您的文件使用适当的内容类型,例如application/zip个文件<{1}}