Search code examples
phpzipphpexcelfile-permissionsphp-ziparchive

ZipArchive generating temp files but not writing content and no error given


I'm using PHPExcel to generate Excel files but it's not working. I have debugged down to this piece of code:

$objZip = new ZipArchive();

$ro = new ReflectionObject($objZip);
$zipOverWrite = $ro->getConstant('OVERWRITE');
$zipCreate = $ro->getConstant('CREATE');

// Try opening the ZIP file
// Debug result: both open() return true here
if ($objZip->open($pFilename, $zipOverWrite) !== true) {
    if ($objZip->open($pFilename, $zipCreate) !== true) {
        throw new PHPExcel_Writer_Exception("Could not open " . $pFilename . " for writing.");
    }
}

// Debug result: $objZip->close() would return true here

// Add [Content_Types].xml to ZIP file
// Debug result: it stops running on this line, no errors or exceptions
$objZip->addFromString('[Content_Types].xml', ...);

The line $objZip->addFromString() generates temp files in the directory, but it seems unable to write into these files somehow, as they are empty:

-rw-------. 1 www1 www1 0 Mar 27 15:21 test_output_20170327.xlsx.0BRqEn
-rw-------. 1 www1 www1 0 Mar 27 15:21 test_output_20170327.xlsx.3Hbl1n
-rw-------. 1 www1 www1 0 Mar 27 15:21 test_output_20170327.xlsx.5otErm
...

Presumably it's a permission issue, but the PHP user www1 has write permission in the directory and fwrite() works well on these temp files as I tried. PHP version is 5.4.16.

Any ideas please?


Solution

  • Turned out to be a problem in PHP update. Resolved by restarting the web server.