2009-04-21 56 views
11

這是我的問題。我正在嘗試調用一個頁面:foo.php?docID = bar並將PDF返回到作爲BLOB存儲在數據庫中的屏幕。IE(HTTPS):從PHP文件生成PDF不起作用

這裏是我的代碼實際上返回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)上,並輸入網址轉到此頁面,它會說已完成,但我仍然會在我的屏幕上顯示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。

由於提前,

〜扎克

+0

我想通了這個問題。看到我的解釋如下 – 2009-04-21 18:55:33

回答

19

我想出了問題所在。這是一個處理IE,HTTPS和插件的IE錯誤。 (見here

這是一個緩存問題。當我設置:

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

(見here),該PDF是緩存足夠長的時間的Adobe Reader插件抓住它。

-2

我認爲你需要添加更多的標頭。

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

我沒有試圖創建它作爲下載(即有保存窗口彈出)。我只是希望它可以通過瀏覽器內的Adobe Reader進行查看。 – 2009-04-21 15:53:55

+0

嘗試取出強制下載和下載標頭,然後 – Matt 2009-04-21 16:06:50

+0

您是否允許使用多個Content-Type標頭? – Calvin 2009-04-21 16:17:54

3

我有這個問題太,我用這似乎做工精細以下

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

試試這個:

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

這是我需要改變的只是標題:

header("Pragma: public"); 
2
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'); 
}