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

后端 未结 12 733
爱一瞬间的悲伤
爱一瞬间的悲伤 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 00:53

    It's caused by dir permission. Try to enter the final folder, then chmod -R 777 [folder_name]. It should work :)

    0 讨论(0)
  • 2020-12-05 00:58

    Excelent Friend Work for me in php 7.1.2 and work in PhpSpreadsheet, fix the same file.

    PhpSpreadsheet/Writer/Excel2007.php
    

    the solution is in de function save in Excel2007.php

    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";
    

    thanks.

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

    I´ve had the same error when I try run my php file, just change the in next line:

    $objWriter->save("/dir1"."/".$file.".xlsx");
    

    for this:

    $objWriter->save(dirname(__FILE__)."/dir1"."/".$file.".xlsx");
    

    add the the dir path and it worked!!!.

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

    In my case, I modify the permissions of the target folder to rwxrwxrwx (0777) and now works!

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

    The most common cause of this error when saving to php://output is an open_basedir restriction that doesn't include a valid system's temp folder (e.g. /tmp), or permissions for the system's temp folder... suhosin can also affect this, even when the obvious permissions appear to be set correctly.

    A possible workround is to write the file to the filesystem in a directory that you know you do have full privileges to write, and then use readfile() to stream that file to php://output before deleting the file

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

    This error happens also when trying to save a file into a folder that doesn't exist. Make sure the whole path exists.

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