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