【问题标题】:Can I create a file download on my html site that only includes the "save" button, not the open button?我可以在我的 html 网站上创建一个只包含“保存”按钮而不是打开按钮的文件下载吗?
【发布时间】:2013-11-01 05:07:32
【问题描述】:

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

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

【问题讨论】:

  • 没有。那是浏览器选项而不是 http 标头。你有没有去过一个你有保存但没有打开选项的网站?

标签: php html file download


【解决方案1】:

试试这个

<?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>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-08-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-12-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多