2014-12-04 69 views
0

我搜索了很多,沒有爲我工作。問題在於文件顯示在瀏覽器中。它包含JSON,但是是一個.locx文件(需要APP)。沒有不是我的APP,所以我不能改變這一點。我已經測試了很多內容類型和編碼的變體,但沒有任何幫助。這是我的守則。Force with PHP下載 - 服務器配置?

<?php 
    function DownloadFile($file) { 
     if(file_exists($file)) { 
      header('Content-Description: File Transfer'); 
      header('Content-Type: application/octet-stream'); 
      header('Content-Disposition: attachment; filename='.basename($file)); 
      header('Content-Transfer-Encoding: binary'); 
      header('Expires: 0'); 
      header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); 
      header('Pragma: public'); 
      header('Content-Length: ' . filesize($file)); 
      ob_clean(); 
      flush(); 
      readfile($file); 
      exit; 
     } 

    } 

    DownloadFile('storage/3-3-2.locx'); 
?> 

感謝您的閱讀!

// UPDATE

它在另一臺服務器上,並寫在註釋的腳本工作得很好,但我必須在服務器配置改變,它也爲我的作品?

+3

您的代碼適用於Chrome和Firefox瀏覽器 – oliakaoil 2014-12-04 15:04:22

+1

您使用哪種瀏覽器進行測試?例如,我發現Internet Explorer緩存Content-Type標題,並且必須重新啓動才能以不同方式處理內容。 – Phylogenesis 2014-12-04 15:04:26

+1

也適用於Apache/FreeBSD,PHP 5.4。我建議可能看看你的服務器配置和MIME類型.... – 2014-12-04 15:08:44

回答

0

它發生,而上傳文件。

將上傳的文件編碼從utf8更改爲iso時。