I am just posting this as I hate when I find these so high on google without a resolution.
To fix this, you must specify the flags as create or overwrite.
$zipFile->open("download.zip", ZIPARCHIVE::CREATE | ZIPARCHIVE::OVERWRITE);
Example:
function zip_magento() {
$zip = new ZipArchive() ;
$opened = $zip->open($this->export_dir.'client_'.$this->uniqueID.'/all.zip', ZIPARCHIVE::CREATE | ZIPARCHIVE::OVERWRITE );
if( $opened !== true ){
echo("cannot open $filename for writing.");
}
//if ($zip->open($this->export_dir.'client_'.$this->uniqueID.'/all.zip',ZIPARCHIVE::CREATE | ZIPARCHIVE::OVERWRITE) !== TRUE) {
// echo ("Could not create archive");
//}
foreach($this->files as $k=>$data){
$zip->addFile($data);
}
$zip->close();