【问题标题】:IE (HTTPS): generating pdf from php file doesn't workIE (HTTPS):从 php 文件生成 pdf 不起作用
【发布时间】:2010-10-20 20:57:59
【问题描述】:

这是我的问题。我正在尝试调用一个页面: foo.php?docID=bar 并将 PDF 返回到屏幕,该屏幕作为 BLOB 存储在数据库中。

这是我的代码中实际返回 PDF 的部分:

$docID = isset($_REQUEST['docID']) ? $_REQUEST['docID'] : null;

if ($docID == null){
    die("Document ID was not given.");
}

$results = getDocumentResults($docID);

if (verifyUser($user, $results['ProductId'])){
    header('Content-type: application/pdf');
    // this is the BLOB data from the results.
    print $results[1];
}
else{
    die('You are not allowed to view this document.');
}

这在 Firefox 中运行良好。

但是,在 IE 中,它根本不显示任何内容。如果我在另一个页面(即 google.com)上,并且我输入 URL 以转到此页面,它会说它已完成,但我的屏幕上仍然会显示 google.com。

我检查了来自 firefox 和 IE 的响应的标题。它们是相同的。

有人有什么建议吗?需要更多信息?

编辑:如果有帮助,这里是响应标题和内容的第一行:

HTTP/1.1 200 OK
Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0
Pragma: no-cache
Content-Length: 349930
Content-Type: application/pdf
Expires: Thu, 19 Nov 1981 08:52:00 GMT
Server: Microsoft-IIS/6.0
X-Powered-By: PHP/5.1.2
Set-Cookie: PHPSESSID=cql3n3oc13crv3r46h2q04dvq4; path=/; domain=.example.com
Content-Disposition: inline; filename='downloadedFile.pdf'
X-Powered-By: ASP.NET
Date: Tue, 21 Apr 2009 16:35:59 GMT

%PDF-1.4

编辑:另外,提取pdf文件的页面实际上使用的是HTTPS而不是HTTP。

提前致谢,

~扎克

【问题讨论】:

  • 我发现了问题所在。请参阅下面的解释

标签: php internet-explorer pdf https


【解决方案1】:

我发现了问题所在。这是一个处理 IE、HTTPS 和插件的 IE 错误。 (见here

这是一个缓存问题。当我设置时:

  header("Cache-Control:  max-age=1");
  header("Pragma: public");

(请参阅here),PDF 在缓存中的时间足够长,以至于 adobe reader 插件可以抓取它。

【讨论】:

  • 对于任何偶然发现此问题或类似问题的 .NET 用户,请参阅此处:stackoverflow.com/questions/1038707/…
  • +1 - 对 csv 文件有类似的问题。这解决了它。谢谢!
  • +1000000 - 搜索高低,这是唯一为我解决它的组合!
  • 并且您需要禁用“不要将加密页面保存到磁盘”选项!
【解决方案2】:

我也遇到了这个问题,我用了以下似乎工作正常

header("Content-type: application/pdf");
header("Content-Length: $length");
header("Content-Disposition: inline; filename='$filename'");

【讨论】:

  • 这似乎也不起作用。内容长度不包括标题,对吗?另外, $filename 只是任意的,对吗?我只是称它为下载文件.pdf。
【解决方案3】:

试试这个:

 header("Content-Type: application/pdf");
 header("Content-Disposition: inline; filename=foo.pdf");
 header("Accept-Ranges: bytes");
 header("Content-Length: $len");
 header("Expires: 0");
 header("Cache-Control: private");

另外,如果你正在使用会话,你可以尝试设置

session_cache_limiter("none");

session_cache_limiter("private");

【讨论】:

    【解决方案4】:
    if ( USR_BROWSER_AGENT == 'IE' ) {
        header( 'Content-Disposition: inline; filename="' . $name . '"');
        header( 'Expires: 0' );
        header( 'Cache-Control: must-revalidate, post-check=0, pre-check=0' );
        header( 'Pragma: public' );
    } else {
        header( 'Content-Disposition: attachment; filename="' . $name . '"' );
        header( 'Expires: 0' );
        header( 'Pragma: no-cache' );
    }
    

    【讨论】:

      【解决方案5】:

      这是我唯一需要更改的标题:

      header("Pragma: public");
      

      【讨论】:

        【解决方案6】:

        我认为您需要添加更多标题。

        header("Content-Type: application/force-download");
        header("Content-Type: application/octet-stream");
        header("Content-Type: application/download");
        header("Content-Disposition: attachment; filename=THEFILENAME.pdf;");
        header("Content-Transfer-Encoding: binary");
        header("Content-Length: " . strlen($results[1]));
        

        【讨论】:

        • 我不想将其创建为下载(即弹出保存窗口)。我只是想让 adobe reader 在浏览器中查看它。
        • 尝试取出 force-download 并下载 header 然后
        • 是否允许使用多个 Content-type 标头?
        • 另外,“force-download”和“download”似乎不是注册的应用媒体类型:iana.org/assignments/media-types/application
        猜你喜欢
        • 2010-11-15
        • 2014-09-29
        • 1970-01-01
        • 2022-12-30
        • 1970-01-01
        • 1970-01-01
        • 2015-08-07
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多