PHPExcel下载文件在实时服务器中提供错误,因为文件扩展名不正确

问题描述 投票:0回答:1

我正在使用PHPExcel库在CodeIgniter框架中下载excel表。它在本地服务器上正常工作,下载excel表文件,打开并显示正确的数据,现在当我在实时服务器中运行相同的代码时,它正在下载,当我打开该文件时,它正在给出此错误,您正在尝试的文件打开'filename.xsl'的格式与文件扩展名指定的格式不同。在打开文件之前验证文件是否已损坏且来自可信来源。

这是代码。

$this->excel->createSheet();
$this->excel->setActiveSheetIndex(2);
$filename='Monthly Report'.date("m-d-Y, h:i:s").'.xls';
header('Content-Type: application/vnd.ms-excel');
header('Content-Disposition: attachment; filename="'.$filename.'"');
header('Cache-Control: max-age=0');
$objWriter = PHPExcel_IOFactory::createWriter($this->excel, 'Excel5');
$objWriter->save('php://output');

我在$ objWriter之前也使用了method ob_end_clean();,仍然遇到了同样的错误。任何帮助将不胜感激。[它在本地服务器上的实时服务器上工作正常]

php codeigniter phpexcel
1个回答
0
投票

ob_end_clean(); ob_start();

在$ objWriter-> save('php:// output')之前使用上面的代码行;它起作用了。

© www.soinside.com 2019 - 2024. All rights reserved.