我有一个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