我有一個excel文件,我希望用戶能夠從我的服務器上下載。我已經看了很多這裏的問題,但我找不到正確下載文件W/O腐敗的方式。我假設它是標題,但我還沒有他們的工作組合。這就是我現在所擁有的,並且在我收到的損壞文件中,我可以看到我想要的電子表格的列名,但它的全部都搞砸了。PHP下載excel文件變得腐敗
$filename = '/var/www/web1/web/public/temporary/Spreadsheet.xls';
header("Content-type: application/octet-stream");
header("Content-type: application/vnd-ms-excel");
header("Content-Disposition: attachment; filename=ExcelFile.xls;");
header("Pragma: no-cache");
header("Expires: 0");
readfile($filename);
編輯:解我忘了補充一點,我使用Zend和嘗試使用本地PHP方法,當它被破壞的文件。我finsihed代碼是放置一個鏈接到我的控制器中的另一個動作,並有文件從那裏
public function downloadAction(){
$file = '/var/www/web1/web/public/temporary/Spreadsheet.xls';
header('Content-Type: application/vnd.ms-excel');
header('Content-Disposition: attachment; filename="Spreadsheet.xls"');
readfile($file);
// disable the view ... and perhaps the layout
$this->view->layout()->disableLayout();
$this->_helper->viewRenderer->setNoRender(true);
}
:
所以,整個文件應包括?輸出2個內容頭文件並非直接文件下載 – 2012-01-31 17:26:02
毫無意義 - 文件不能一次成爲兩件事。這就像說「我是長頸鹿和鯨魚!」。 – 2012-01-31 17:26:08
很長時間以來,對這類問題的最常見答案歸結爲以下兩種情況之一:a)在腳本中的''標記之前/之後或在您的腳本中有一個BOM表之前/之後有前/後空白/ HTML文件或b)在'readfile()'之後忘記調用'exit' /'die',並在文件數據的末尾輸出更多內容。 – DaveRandom 2012-01-31 17:27:24