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


Can I create a file download on my html site that only includes the "save" button, not the open button?

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

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

试试这个

<?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");
?>

将此代码放在另一个文件中 say 文件中.php然后使用锚标记调用它

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