php - ZipArchive::getStatusString(): Invalid or uninitialized Zip object -
the following code fail create zip file in php 5.6.12 , fail print out zip error message, instead displaying error / warning
warning: ziparchive::getstatusstring(): invalid or uninitialized zip object in /tmp/x.php on line 9
but why? once worked in php 5.4.
<?php // todo: check errors $temppath = tempnam('/tmp', 'ztmp'); $zip = new ziparchive(); $res = $zip->open($temppath, ziparchive::overwrite | ziparchive::create | ziparchive::excl); if ( $res !== true ) die($zip->getstatusstring()."\n");
it looks semantics have changed somewhat; unclear whether deliberate or bug.
anyways, problem have empty file not valid zip being opened nonetheless , not initialized though requested file overwritten.
so workaround or fix delete existing file , recreate it:
<?php $temppath = tempnam('/tmp', 'ztmp'); // delete first @unlink($temppath); $zip = new ziparchive(); $res = $zip->open($temppath, ziparchive::overwrite | ziparchive::create | ziparchive::excl); if ( $res !== true ) die($zip->getstatusstring()."\n");
Comments
Post a Comment