IE (HTTPS):从 php 文件生成 pdf 不起作用

发布于 2024-07-18 04:10:55 字数 1373 浏览 4 评论 0原文

这是我的问题。 我正在尝试调用页面: foo.php?docID=bar 并将 PDF 返回到屏幕,该 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 的。

预先感谢,

〜扎克

Here is my issue. I am trying to call a page: foo.php?docID=bar and return a PDF to the screen which is stored as a BLOB in the DB.

Here is the portion of my code which actually returns the 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.');
}

This works perfectly fine in Firefox.

However, in IE, it doesn't show anything at all. If i'm on another page (i.e. google.com), and I type in the URL to go to this page, it will say it's done, but I will still have google.com on my screen.

I checked the headers for the responses from both firefox and IE. They are identical.

Does anyone have any suggestions? Need more information?

EDIT: If it helps at all, here's the response header and the first line of the content:

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

EDIT: Also, the page which pulls out the pdf file actually uses HTTPS instead of HTTP.

Thanks in advance,

~Zack

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

旧伤还要旧人安 2024-07-25 04:10:55

我明白了问题所在。 这是一个处理 IE、HTTPS 和插件的 IE 错误。 (请参阅此处

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

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

参见此处)时,PDF位于缓存足够长的时间,以便 adobe reader 附加组件能够获取它。

I figured out what the issue was. It's an IE bug dealing with IE, HTTPS and addons. (See here)

It was a caching issue. When I set:

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

(see here), the PDF was in cache long enough for the adobe reader add-on to grab it.

初心未许 2024-07-25 04:10:55

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

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

I had this issue too, i used the following which seems to work fine

header("Content-type: application/pdf");
header("Content-Length: $length");
header("Content-Disposition: inline; filename='$filename'");
天生の放荡 2024-07-25 04:10:55

试试这个:

 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");

Try this:

 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");

Also, if you are using sessions, you can try setting

session_cache_limiter("none");

or

session_cache_limiter("private");
夏九 2024-07-25 04:10:55
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' );
}
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' );
}
弃爱 2024-07-25 04:10:55

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

header("Pragma: public");

This was the only header I needed to change:

header("Pragma: public");
淡水深流 2024-07-25 04:10:55

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

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]));

I think you need to add more headers.

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]));
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文