2013-01-14 32 views
0

工作在我的項目的Excel佈局我添加CakePHP的2.1 XLS頭內容類型沒有在Mac的Safari

 <?php 

     header ("Last-Modified: " . gmdate("D,d M YH:i:s") . " GMT"); 
     header ("Cache-Control: no-cache, must-revalidate"); 
     header ("Pragma: no-cache"); 
     header ("Content-type: application/vnd.ms-excel");/*.pdf,.xls*/ 
     header ("Content-Disposition: attachment; filename=Report.xls"); 
     header ("Content-Description: Generated Report"); 
    ?> 
    <?php echo $content_for_layout ?> 

,並在我的控制器

 function export_xls($id=null) { 
     $this->render('export_xls', 'export_xls'); 
    } 

和export_xls.ctp保持空白。

在Windows中,它創造的report.xls文件,但MAC OS的Safari瀏覽器下載它作爲report.xls.html 什麼該做,我不understand.i我使用CakePHP 2.1

請幫我解決這個問題.....

+0

您是否試過[Media View](http://book.cakephp.org/2.0/en/views/media-view.html)? – noslone

+0

我使用該媒體視圖,但它不起作用。 –

+0

你需要設置正確的'mimeType'或者離開它。如果CakePHP知道'mimeType',CakePHP會自動填充'mimeType' – noslone

回答

0

需要在.ctp或export_xls函數中有內容。你實際上並沒有輸出任何文件來工作。

0

您的標題看起來不錯(儘管我認爲Content-type應該是Content-Type),但請嘗試使用Cake內置的響應類。適用於我的XLS文件。在您的控制器中:

$this->response->file($path,array('download' => true, 'name' => 'Report.xls')); 
return $this->response; 
相關問題