PHPExcel_Writer_Exception with message “Could not close zip file php://output.”

后端 未结 12 759
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-12-05 00:30

I\'m using PHPExcel to export some data to user in an excel file. I would like the script to send the excel file to the user immediately after it\'s creation. Here is my tes

12条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-05 01:16

    Thanks to Mark Baker. His answer has solved the problem. I have written a simple helper method using his approach.

    static function SaveViaTempFile($objWriter){
        $filePath = sys_get_temp_dir() . "/" . rand(0, getrandmax()) . rand(0, getrandmax()) . ".tmp";
        $objWriter->save($filePath);
        readfile($filePath);
        unlink($filePath);
    }
    

    And I have just replaced $objWriter->save('php://output') with SaveViaTempFile($objWriter)

提交回复
热议问题