note 86131 added to zip.examples

From: Date: Sat, 04 Oct 2008 14:13:57 +0000
Subject: note 86131 added to zip.examples
Groups: php.notes 
Request: Send a blank email to php-notes+get-145047@lists.php.net to get a copy of this message
1) If you want to add files to a ZIP archive but you don't know if the ZiP file exists or not, you MUST check: this changes the way you open it !. 2) you can not append multiple flags, can use only one (or none). If the zip does not exists, open it with: $ziph->open($archiveFile, ZIPARCHIVE::CM_PKWARE_IMPLODE) (or a different compression method) If the zip already exists, open it with: $ziph->open($archiveFile) or $ziph->open($archiveFile, ZIPARCHIVE::CHECKCONS) Example: make backup files every hour and ZIP them all in a daily ZIP archive, so you want to get only one ZIP per day, each ZIP containing 24 files: <?php function archivebackup($archiveFile, $file, &$errMsg) { $ziph = new ZipArchive(); if(file_exists($archiveFile)) { if($ziph->open($archiveFile, ZIPARCHIVE::CHECKCONS) !== TRUE) { $errMsg = "Unable to Open $archiveFile"; return 1; } } else { if($ziph->open($archiveFile, ZIPARCHIVE::CM_PKWARE_IMPLODE) !== TRUE) { $errMsg = "Could not Create $archiveFile"; return 1; } } if(!$ziph->addFile($file)) { $errMsg = "error archiving $file in $archiveFile"; return 2; } $ziph->close(); return 0; } ?> ---- Server IP: 69.147.83.197 Probable Submitter: 87.10.65.182 ---- Manual Page -- http://www.php.net/manual/en/zip.examples.php Edit -- https://master.php.net/note/edit/86131 Del: integrated -- https://master.php.net/note/delete/86131/integrated Del: useless -- https://master.php.net/note/delete/86131/useless Del: bad code -- https://master.php.net/note/delete/86131/bad+code Del: spam -- https://master.php.net/note/delete/86131/spam Del: non-english -- https://master.php.net/note/delete/86131/non-english Del: in docs -- https://master.php.net/note/delete/86131/in+docs Del: other reasons-- https://master.php.net/note/delete/86131 Reject -- https://master.php.net/note/reject/86131 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#145047) next »