我可以在我的html网站上创建一个仅包含“保存”按钮而不是打开按钮的文件下载吗?

时间:2013-11-01 05:07:32

标签: php html file download

我的代码如下。这有效,但我想知道是否有办法排除“打开”按钮并强制用户保存文件。谢谢!

<?php
header("Content-disposition: attachment; filename=myfile.pdf");
header("Content-type: application/pdf");
readfile("myfile.pdf");
?>

1 个答案:

答案 0 :(得分:0)

试试这个

<?php
header("Content-disposition: attachment; filename=myfile.pdf");
header("Content-type: application/pdf");
header('Content-Description: File Transfer');
header('Pragma: public');
header('Expires: 0');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
readfile("myfile.pdf");
?>

将此代码放在另一个文件中,例如file.php,然后使用锚标记

调用它
<a href='file.php'>Download PDF</a>