php强制下载标题

时间:2013-11-21 12:18:50

标签: php download http-headers media

哪些标头最重要的是强制下载以及浏览器自动填充哪些标题

例如

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行以外的所有标题,下载工作正常/为何如何?

1 个答案:

答案 0 :(得分:3)

Content-Disposition: attachment表示您的浏览器内容是附件。因此,浏览器将开始将内容下载为文件。

根据RFC 6266

  

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

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

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

相关问题