note 88765 added to function.ziparchive-open

From: Date: Fri, 06 Feb 2009 15:06:21 +0000
Subject: note 88765 added to function.ziparchive-open
Groups: php.notes 
Request: Send a blank email to php-notes+get-150300@lists.php.net to get a copy of this message
With php 5.2.6, the following code created a new zip or replaced a existing zip. Note that I am only using the ZIPARCHIVE::OVERWRITE flag. <?php $zip = new ZipArchive(); $opened = $zip->open( $zipFileName, ZIPARCHIVE::OVERWRITE ); if( $opened !== true ){ die("cannot open {$zipFileName} for writing."); } $zip->addFromString( $name, $contents ); $zip->close(); ?> Now, with php 5.2.8, it does not work and gives this warning: Warning: ZipArchive::addFromString() [ziparchive.addfromstring]: Invalid or unitialized Zip object in [myfile] on line [myline] To fix this, you must specify the flags as create or overwrite. <?php $zip = new ZipArchive(); $opened = $zip->open( $zipFileName, ZIPARCHIVE::CREATE | ZIPARCHIVE::OVERWRITE ); if( $opened !== true ){ die("cannot open {$zipFileName} for writing."); } $zip->addFromString( $name, $contents ); $zip->close(); ?> When googling for the error message I found a lot of people that had it but couldn't figure out why they were getting it. I hope this helps someone. ---- Server IP: 209.41.74.194 Probable Submitter: 75.145.49.105 ---- Manual Page -- http://www.php.net/manual/en/function.ziparchive-open.php Edit -- https://master.php.net/note/edit/88765 Del: integrated -- https://master.php.net/note/delete/88765/integrated Del: useless -- https://master.php.net/note/delete/88765/useless Del: bad code -- https://master.php.net/note/delete/88765/bad+code Del: spam -- https://master.php.net/note/delete/88765/spam Del: non-english -- https://master.php.net/note/delete/88765/non-english Del: in docs -- https://master.php.net/note/delete/88765/in+docs Del: other reasons-- https://master.php.net/note/delete/88765 Reject -- https://master.php.net/note/reject/88765 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#150300) next »