【问题标题】:php force download headersphp强制下载头文件
【发布时间】:2013-11-21 12:18:50
【问题描述】:

哪些标题对强制下载最重要,哪些标题由浏览器自动填充

例如

header('Content-Description: File Transfer');
header('Content-type: application/zip');
header('Content-Length: '.sprintf("%u", filesize($zip_out)));
header('Content-Transfer-Encoding: binary');
header('Expires: 0');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Pragma: public');
header('Content-Disposition: attachment; filename="'.basename($zip_out).'"');

我省略了除第 1 行和第 2 行之外的所有标题,下载工作正常,为什么/如何??

【问题讨论】:

    标签: php download http-headers media


    【解决方案1】:

    Content-Disposition: attachment 表示您的浏览器内容是附件。所以浏览器会开始以文件的形式下载内容。

    根据RFC 6266

    如果处置类型匹配“附件”(不区分大小写), 这表示收件人应提示用户保存 在本地响应,而不是正常处理它(根据其媒体 类型)。

    Content-type: application/zip 表示您的浏览器内容已压缩,并且通常使浏览器将内容作为文件下载,即使省略了 Content-Disposition: attachment,因为这是浏览器压缩内容的默认行为。

    我从未在任何与 HTTP 相关的规范中看到 Content-Description 标头,我认为它根本不会影响下载。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2023-04-01
      • 2013-06-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-08-03
      • 2010-11-03
      相关资源
      最近更新 更多