User Contributed Notes 5 notes

All these examples will not work if the php script has no write access within the folder.

Although you may say this is obvious, I found that in this case, $zip->open("name", ZIPARCHIVE::CREATE) doesn't return an error as it might not try to access the file system but rather allocates memory.

It is only $zip->close() that returns the error. This might cause you seeking at the wrong end.

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)

If you find your zip file not being created make sure every file you are adding to the zip is valid. If even one file is not available when zip->close is called then the archive will fail and your zip file won't be created.