我需要为最近的项目做到这一点,并且对如何实现有点困惑,但在看到克劳斯的答案后不久就明白了。为了进一步阐述Klaus的回应:
1)创建一个叫做“process.php”的文件。修改Klaus的代码,以便它接受两个参数:原始文件名和新名称。我process.php样子:
<?php
$file = $_GET['file'];
if (file_exists($file)) {
header('Content-Description: File Transfer');
header('Content-Type: application/pdf');
header('Content-Disposition: attachment; filename='.$_GET['newFile']);
header('Content-Transfer-Encoding: binary');
header('Content-Length: ' . filesize($file));
ob_clean();
flush();
readfile($file);
exit;
}
?>
2)创建一个指向处理器脚本的面向用户的页面上的链接:
<a href="process.php?file=OriginalFile.pdf&newFile=MyRenamedFile.pdf">DOWNLOAD ME</a>
'内容type'应该是'内容Type' ,但是。 – jensgram 2009-12-01 15:14:54
@jensgram:不区分大小写。 – BalusC 2009-12-01 15:16:10
@klausbyskov:请参阅BalusC下面的评论。据他说,它不会在IE浏览器上工作? – understack 2009-12-01 15:18:53