Sporadic "Uncaught exception 'Exception' with message 'Could not close zip file "

Topics: Developer Forum, User Forum
Nov 21, 2012 at 11:47 AM

Hi All - I know there have been previous posts on this but it seems they have been resolved by a change in permissions. The problem I have is that this error is sporadic, I can get the following error form my web app and then simply hit refresh on the browser and the next time it's OK - sometimes I get the error first time round and sometimes I don't.

Fatal error: Uncaught exception 'Exception' with message 'Could not close zip file ../data/product/Client US/output/a0f89rcierlpspo83qg1vcni27/Client US_Gloss TB6-Gloss TB6_RIG.xlsx.' in C:\sambar60-1\docs\QA\classes\PHPExcel-latest\PHPExcel\Writer\Excel2007.php:352 Stack trace: #0 C:\sambar60-1\docs\QA\RIG\code\sign_off_generator_gloss.php(217): PHPExcel_Writer_Excel2007->save('../data/product/C...') #1 {main} thrown in C:\sambar60-1\docs\QA\classes\PHPExcel-latest\PHPExcel\Writer\Excel2007.php on line 352

I'm running Sambar on Windows Server 2003, PhpExcel 1.7.8

Has anyone seen this error sporadically and found a solution or workaround?

Many thanks


Nov 21, 2012 at 11:03 PM

Three possible causes that I'm aware of:

  • Invalid directory path
  • File permissions
  • File is open within another application


Nov 22, 2012 at 9:39 AM

Thanks Mark - your point about 'Invalid Directory Paths' made me convert the relative paths that I had been using to absolute paths and for now that seems to have fixed it.

So for any relative php newbies I was using this to save:

$xlsPath = '../data/' . PRODUCT . '/' . $client . '/output/'.session_id().'/';


now I'm using:

$xlsPath = $_SERVER['DOCUMENT_ROOT']."/QA/RIG/data/" . PRODUCT ."/". $client . '/output/'.session_id().'/';


So far this seems to have worked, will post here again if the error re-occurs.


Nov 22, 2012 at 10:13 AM

Spoke too soon. Just seen the same error again..

Dec 12, 2012 at 9:07 AM

Have wrapped the save() function in try / catch and put that inside a loop so that it tretires if the exception is thrown, seems to have worked and I can see from my log files that when the error has been thrown on the first attempt, the second attempt saves successfully.:


        $i = 1;
        while ($i <= 5)

            try {
                $logger->info("Saving the xls file");
                $logger->info("xls file save successful");
            Catch (Exception $e){


                if ($i == 5)
                    $logger->err("Error message: ". $e->getMessage());
                    $logger->err("Error code: ". $e->getCode());
                    $logger->err("Error full string: ". $e->__toString());

                    echo "
EXITING - Full error string:
; die ( $e->__toString() ); } sleep(5); $logger->warning("Caught Error message: ".$e->getMessage()); $logger->warning("Re-attempting the save"); } }