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

后端 未结 12 734
爱一瞬间的悲伤
爱一瞬间的悲伤 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条回答
  • 2020-12-05 01:10

    For some people who may have this same ERROR message : it may very simply be because the filename you're trying to save to is actually already open in your Excel.. Was my case

    0 讨论(0)
  • 2020-12-05 01:11

    Hi i tried the following: in a server linux Centos 7.0 do not specified the route of directory tmp, input:

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

    and work !!

    0 讨论(0)
  • 2020-12-05 01:11

    And my answer is: Filename had symbols such as ":", ",", '"' Had to replace them to different ones. All worked

    0 讨论(0)
  • 2020-12-05 01:11

    set chmod 777 -R public/results

    0 讨论(0)
  • 2020-12-05 01:14

    The following works for the Excel2007 format. It would need to be adapted for different formats.


    Open this file:

    \Classes\PHPExcel\Writer\Excel2007.php
    

    Look near Line 196 for:

    if (strtolower($pFilename) == 'php://output' || strtolower($pFilename) == 'php://stdout') {
        $pFilename = @tempnam(PHPExcel_Shared_File::sys_get_temp_dir(), 'phpxltmp');
    

    Replace the second line with this:

        $pFilename = dirname(\__FILE__).'/'. rand(0, getrandmax()) . rand(0, getrandmax()) . ".phpxltmp";
    

    Then you can use the export-function as described in the developer guide.

    0 讨论(0)
  • 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)

    0 讨论(0)
提交回复
热议问题