【问题标题】:Download File Types Confusion - application/octet-stream下载文件类型混淆 - application/octet-stream
【发布时间】:2011-11-21 02:09:41
【问题描述】:

我正在使用此代码:

header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); // some day in the past
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
header("Content-type: application/octet-stream");
header("Content-Disposition: attachment; filename=".$original);
header("Content-Transfer-Encoding: binary");
readfile('/tmp/'.$original);

从我的服务器 (EC2) 输出已从 S3 抓取的文件。这适用于图像和 .txt 文件,但 PDF 和 .doc 似乎以某种方式损坏。他们不会打开,或者如果他们打开内容是乱码。

我认为这一定与内容类型 application/octet-stream 有关?然而,我在这方面的知识有限——我已经做了一些阅读和反复试验,但我没有进一步前进。

在 S3 中,所有文件的内容类型都设置为 application/octet-stream。我也不确定这是否正确(这不是我在上传文件时设置的)

任何想法表示赞赏。

谢谢

【问题讨论】:

  • 下载无误的文件类型有 jpeg、txt 和 rtf。我收到 doc 和 pdf 错误。

标签: php amazon-s3 amazon-ec2 download


【解决方案1】:

.doc 文件应设置application/msword,.pdf 文件应设置application/pdf

【讨论】:

    【解决方案2】:
    <?php
    header('Content-type: application/pdf'); // set content type
    header('Content-Disposition: attachment; filename="downloaded.pdf"'); // force download
    readfile('original.pdf'); // read the content to server
    ?>
    

    来源:http://php.net/manual/en/function.header.php

    【讨论】:

      猜你喜欢
      • 2010-12-28
      • 2023-03-22
      • 1970-01-01
      • 2013-12-28
      • 2018-09-11
      • 2021-11-15
      • 2019-10-16
      • 2016-11-23
      相关资源
      最近更新 更多