我在我的網頁上有一個鏈接,用於下載我在服務器上生成的.CSV文件。下載代碼如下:帶有內容處理的PHP文件下載問題:附件
//open/save dialog box
header('Content-Disposition: attachment; filename="inventoryData.csv"');
//content type
header('Content-type: application/excel');
//read from server and write to buffer
readfile('spreadsheet/inventory.csv');
當我打開服務器上的文件,它看起來就好。但是,當我通過對話框下載文件時,它將網頁的HTML代碼預先等待到.csv文件。
任何想法爲什麼會發生?
你確定沒有其他代碼被回顯出來嗎? – ku6pk
'application/excel'應該是['text/csv'](http://www.rfc-editor.org/rfc/rfc4180.txt)。 – Quentin
您可能在php.ini中啓用了HTML錯誤。 –