2011-04-27 35 views
0

我有我的一個PHP腳本,它可以在Windows上正常工作以強制從外部鏈接文件下載文件。我的意思是在我的電腦上下載,並閱讀donwloaded文件做得好 但在我的Ubuntu下相同的代碼下載,但閱讀它是一個大問題。我有以下錯誤與「侏儒之眼」:=錯誤解釋JPEG圖像文件JPEG文件:用0x70爲0x3C開始)= 也許我不得不改變標題我想是這樣buttt ...任何想法都歡迎THX在ubuntu上的php下載

// required for IE, otherwise Content-disposition is ignored  
if (ini_get('zlib.output_compression')) 
      ini_set('zlib.output_compression', 'Off'); 

// addition by Jorg Weske 
     //$file_extension = strtolower(substr(strrchr($filename, "."), 1)); 
     header("Pragma: public"); // required 
     header("Expires: 0"); 
     header("Cache-Control: must-revalidate, post-check=0, pre-check=0"); 
     header("Cache-Control: private", false); // required for certain browsers 
     header("Content-Type: application/force-download; name=\"$filename\""); 
// change, added quotes to allow spaces in filenames, by Rajkumar Singh 
     header("Content-Disposition: attachment; filename=\"" . basename($filename) . "\";"); 
     header("Content-Transfer-Encoding: binary"); 
//header("Content-Length: ".filesize($filename)); 
     readfile("$filename"); 
     exit(); 
+0

查看JPEG文件:有可能是PHP錯誤打破了數據流。 – 2011-04-27 09:08:23

+0

下載的文件有哪些* *?嘗試'文件'。 – 2011-04-27 09:09:09

+0

'application/force-download'是無效的,以及那裏的'name ='參數。別管它吧。無論如何,你已經擁有了正確的「Content-Disposition:」標題。 – mario 2011-04-27 09:12:27

回答

1

0x3c 0x70 = <P。你確定你的PHP腳本在JPEG數據之前沒有發送任何HTML嗎?該腳本還可能會生成警告或通知,並在JPEG數據之前發送。