下载文件到服务器 phpexcel + codeigniter
download file to server phpexcel + codeigniter
我无法将 PHPExcel 生成的文件保存到服务器。什么时候做
$this->load->library('Classes/PHPExcel');
$this->phpexcel->getActiveSheet()->setCellValue('A5','Value');
more excel code...
$writer = new PHPExcel_Writer_Excel5($this->phpexcel);
header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
header('Content-Disposition: attachment; filename="newFile.xls"');
header('Cache-Control: max-age=0');
$writer->setPreCalculateFormulas(false);
$writer->save('php://output');
我可以下载文件,但我尝试了很多不同的方法将文件保存在服务器文件夹中,例如
$filename = 'file.xls';
$writer = new PHPExcel_Writer_Excel5($this->phpexcel);
header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
header('Content-Disposition: attachment; filename="newFile.xls"');
header('Cache-Control: max-age=0');
$writer->setPreCalculateFormulas(false);
$writer->save($filename);
或使用PHPExcel_IOFactory保存文件,但我无法让它工作,同样的想法。
问候。
试试这个:
header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
header('Content-Disposition: attachment;filename="'.$fname.'"');
header('Cache-Control: max-age=0');
$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');
$objWriter->save('./files/'.$fname);
昨晚我解决了错误。
$writer = new PHPExcel_Writer_Excel5($this->phpexcel);
header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
header('Content-Disposition: attachment; filename="newFile.xls"');
header('Cache-Control: max-age=0');
$writer->setPreCalculateFormulas(false);
$writer->save(getcwd().'/mailAttachment/newFile.xls');
我添加了这一行。
$writer->save(getcwd().'/mailAttachment/newFile.xls');
函数 getcwd() 获取当前工作目录。
谢谢。
我无法将 PHPExcel 生成的文件保存到服务器。什么时候做
$this->load->library('Classes/PHPExcel');
$this->phpexcel->getActiveSheet()->setCellValue('A5','Value');
more excel code...
$writer = new PHPExcel_Writer_Excel5($this->phpexcel);
header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
header('Content-Disposition: attachment; filename="newFile.xls"');
header('Cache-Control: max-age=0');
$writer->setPreCalculateFormulas(false);
$writer->save('php://output');
我可以下载文件,但我尝试了很多不同的方法将文件保存在服务器文件夹中,例如
$filename = 'file.xls';
$writer = new PHPExcel_Writer_Excel5($this->phpexcel);
header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
header('Content-Disposition: attachment; filename="newFile.xls"');
header('Cache-Control: max-age=0');
$writer->setPreCalculateFormulas(false);
$writer->save($filename);
或使用PHPExcel_IOFactory保存文件,但我无法让它工作,同样的想法。
问候。
试试这个:
header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
header('Content-Disposition: attachment;filename="'.$fname.'"');
header('Cache-Control: max-age=0');
$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');
$objWriter->save('./files/'.$fname);
昨晚我解决了错误。
$writer = new PHPExcel_Writer_Excel5($this->phpexcel);
header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
header('Content-Disposition: attachment; filename="newFile.xls"');
header('Cache-Control: max-age=0');
$writer->setPreCalculateFormulas(false);
$writer->save(getcwd().'/mailAttachment/newFile.xls');
我添加了这一行。
$writer->save(getcwd().'/mailAttachment/newFile.xls');
函数 getcwd() 获取当前工作目录。
谢谢。