ZipArchive warning

Topics: Developer Forum
Nov 8, 2012 at 2:03 PM


I'm having a problem I can see other people have got, but haven't been able to find a solution yet.

I can't open the generated Excel file in Excel (Nor on Mac or Windows), only if I save it to the server first.

I've looked for any addtional echo's or so, that could generate premature output, but there's nothing there. And as far as I can see, php_zip is enabled.

The warning I get is

ZipArchive::open(): Unable to access php://output in PHPExcel/Writer/Excel2007.php


Fatal Error: Uncaught exception 'Exception' with message 'Could not open php://output for writing' in PHPExcel/Writer/Excel2007.php:248 Stack trace:#0

Nov 8, 2012 at 10:46 PM

php://output is one of the standard PHP stream wrappers and I've not encountered any circumstance where it should not be available. It sounds more like a fundamental problem in PHP than in PHPExcel: as far as PHPExcel is concerned php://output is just another file stream, though one that should always be available.


Does anybody else have this problem?

Jan 18, 2013 at 10:41 AM
Edited Jan 18, 2013 at 10:54 AM

I have exactly the same problem as MartinHjort described.

I found out that the PHP SAFE MODE caused this problem. PHPExcel could not write to the tmp folder. But after deactivating SAFE MODE I got another error: 

Fatal error: Uncaught exception 'Exception' with message 'Could not close zip file php://output.' in /home/.sites/92/site955/web/library/PHPExcel/PHPExcel/Writer/Excel2007.php:378 Stack trace: #0 /home/.sites/92/site955/web/test/memberlist.php(98): PHPExcel_Writer_Excel2007->save('php://output') #1 {main} thrown in /home/.sites/92/site955/web/library/PHPExcel/PHPExcel/Writer/Excel2007.php on line 378

Does anybody have a solution for this problem?

Jan 18, 2013 at 11:00 AM

Check permissions in the temp folder

Jan 18, 2013 at 11:12 AM

I don't really have access to the temp folder, or at least it's getting complicated with my provider.

As a workaround I activated SAFE MODE again and I save the file in the working directory of the php file and open it using the readfile command. This works as expected. 

May 3, 2013 at 9:26 AM
As of PHP 5.3.0, php_zip is built-in. The extension is not working anymore. Directing your ZipArchive to the PHPExcel built-in zip archive (add 'PHPExcel_Settings::setZipClass(PHPExcel_Settings::PCLZIP);' before the call to the save function) will solve the problem with writing excel files in Excel2007 format. The only problem that exists is the fact that some unreadable content will be included causing excel to give a warning on opening the file, asking to repair the file. Just say 'yes' and you will have a readable excel file. Something to correct in future versions?
Jan 29, 2014 at 3:38 AM
I also have the same problem and no idea how to fix it. I can manipulate files in other ways on this website and this code also worked on another development server.

I have checked all permissions to the /QS-admin and to /QS-admin/excel.

I tried this from mrbladergroen ... now I get a different error.
Fatal error: Uncaught exception 'Exception' with message 'Error zipping files : PCLZIP_ERR_READ_OPEN_FAIL (-2) : Unable to open archive '/QS-admin/excel/QuiltsExport_123792273.xlsx' in wb mode' in /home/marepinta/ Stack trace: #0 /home/marepinta/ PHPExcel_Shared_ZipArchive->addFromString('[Content_Types]...', '<?xml version="...') #1 /home/marepinta/ PHPExcel_Writer_Excel2007->save('/QS-admin/excel...') #2 {main} thrown in /home/marepinta/ on line 108
I'm looking for some help with troubleshooting. What steps to take to isolate the problem and then be able to move forward :)

Jan 29, 2014 at 3:56 AM
read a few more archived posts about this problem.

someone said to pay attention to folder addresses.

I changed the virtual folder to actual folder address and now it works. Thanks!!

for newbies ... this means I changed:

/QS-admin/excel/[new filename]


/home/marepinta/[new filename]