2012-03-05 76 views
0

我想使用MIME代碼下載完整的網頁。我使用PHP幫助 - MIME代碼?

header("Content-type:application/msword"); 
header("Content-Disposition:attachment; Filename=$profile_id.doc"); 

下載網頁在MS Word和我想:

header("Content-type:application/pdf"); 
header("Content-Disposition:attachment; Filename=$profile_id.pdf"); 

下載網頁中的PDF,但PDF一個不工作。請告訴我該怎麼做......謝謝:)

我認爲現在這個代碼已經被棄用了。請讓我知道TH這

+0

http://stackoverflow.com/questions的可能的複製/ 312230 /適當的mime-type-for-pdf-files – rkosegi 2012-03-05 12:15:07

+0

你的問題到底是什麼?你正確輸出一個pdf二進制流? – 2012-03-05 12:15:52

+0

傑羅姆...沒有先生,我沒有得到正確的輸出PDF文件的情況下......文件被下載,但格式不正確,所以它不在Acrobat Reader中打開 – 2012-03-05 12:18:03

回答

0

嘗試替代代碼:

 

header('Content-Type:application/pdf'); 
header('Content-Disposition:attachment; filename="'.$profile_id.'.pdf"'); 
 

編輯: 嘗試,是這樣的:

 

$file = $profile_id.".pdf"; 
header ("Cache-Control: must-revalidate, post-check=0, pre-check=0"); 
header('Content-Type: application/octetstream'); 
header("Content-Transfer-Encoding: Binary"); 
header("Content-length: ".filesize($file)); 
header('Content-Disposition:attachment; filename="'.$profile_id.'.pdf"'); 

 
+0

@OP:是,或包裝在{}中的變量,所以解析器可以看到哪些位意味着變量:) – halfer 2012-03-05 12:18:58

+0

Sudhir先生...我試過了... header(「Content-Disposition:attachment; Filename = $ profile_id.pdf」 ); 正常工作,但不是 「header('Content-Type:application/pdf');」 – 2012-03-05 12:22:10

+0

看到編輯過的部分,希望它能正常工作 – 2012-03-05 12:27:56