我在我的网页上有一个链接,用于下载我在服务器上生成的.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错误。 –