2011-09-20 54 views
1

我使用這個代碼:下載文件類型的困惑 - 應用程序/八位字節流

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似乎以某種方式被損壞。他們不會打開,或者如果他們做的內容是亂碼。

我在想,它必須與內容類型的應用程序/八位字節流?然而,我的知識在這方面是有限的 - 我已經做了一些閱讀和試驗和錯誤,但我沒有進一步前進。

在S3中,將所有文件的內容類型設置爲application/octet-stream。我不知道這是否正確(這不是我上傳文件時設置的東西)

任何想法讚賞。

感謝

+0

文件類型無誤地下載是jpeg,txt和rtf。我遇到doc和pdf錯誤。 –

回答

1

爲.doc文件,你應該設置應用程序/ msword,爲.pdf文件,你應該設置應用/ PDF

0
<?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

相關問題