我的代码如下。这有效,但我想知道是否有办法排除“打开”按钮并强制用户保存文件。谢谢!
<?php
header("Content-disposition: attachment; filename=myfile.pdf");
header("Content-type: application/pdf");
readfile("myfile.pdf");
?>
答案 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>