PHP Create a ZIP file

I was just playing around with PHP’s ability to create compressed files, and I had a problem. My ZIP file was not getting created but I wasn’t getting any errors.

$zip = new ZipArchive();
$zipFile = '/tmp/' . uniqid() . '.zip';

if (file_exists($zipFile)) {

$zip->open($zipFile, ZIPARCHIVE::CREATE);

foreach ($files as $type => $file) {


Now, pay particular attention to the files you are adding using addFile() as if you have entered them wrong, you won’t get an error message, and infact, if you use $zip->getStatusString() you will receieve a “No error” message – completely throwing you off the scent.

More information about ZipArchive can be found at

Leave a Reply

Your email address will not be published.

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

This site uses Akismet to reduce spam. Learn how your comment data is processed.