【问题标题】:Mobile browsers are adding .html to filename on download移动浏览器在下载时将 .html 添加到文件名
【发布时间】:2022-05-05 13:22:39
【问题描述】:

出于某种原因,使用以下代码:

header("Content-Type: text/x-vcard;charset=utf-8;");
header("Content-Disposition: attachment; filename=card.vcf");
header("Pragma: no-cache");
header("Expires: 0");

echo $vcard_serialized;

在电脑上的 chrome 上,它下载 card.vcf,但从手机上它下载 card.vcf.html...为什么?

【问题讨论】:

  • 输出中是否有任何意外的 HTML 内容?
  • @ADyson 不,只有 vcf 内容...我看到类似的答案 stackoverflow.com/questions/19363744/… 但如果我使用它,Safari 会告诉我“Safari 无法下载此文件”
  • 那个链接似乎是回到这个问题的链接......
  • @ADyson 我的错,已编辑
  • 所以你的意思是如果你最后使用exit; Safari 会抱怨?

标签: php file mobile file-extension vcf-vcard


【解决方案1】:

我有同样的问题,但现在我已经使用以下代码修复了它:

header('Content-Description: Download vCard');
header('Content-Type: text/vcard');
header('Content-Disposition: attachment; filename='.$your_filename_here);
header('Content-Transfer-Encoding: binary');
header('Expires: 0');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Pragma: public');
ob_clean();
flush();
echo $vcard_serialized; //echo the content
exit;

【讨论】:

    猜你喜欢
    • 2020-03-17
    • 1970-01-01
    • 1970-01-01
    • 2014-03-27
    • 1970-01-01
    • 2019-05-15
    • 1970-01-01
    • 2013-03-17
    • 2013-10-18
    相关资源
    最近更新 更多