PHP Classes

Error creating ZIP file bigger then 1Mb

Recommend this page to a friend!

      Zip  >  All threads  >  Error creating ZIP file bigger then 1Mb  >  (Un) Subscribe thread alerts  
Subject:Error creating ZIP file bigger then 1Mb
Summary:Creation of Zip file known as corrupt or unknown format??
Date:2011-01-28 14:30:03
Update:2011-01-28 15:05:21

  1. Error creating ZIP file bigger then 1Mb   Reply   Report abuse  
matteo09 - 2011-01-28 14:30:03
i'm facing since many hours with these problem:
When i create a ZIP file that will be bigger than 1024Kb the browser say the following error:
"ERROR: The archive is damaged or its format is unknown."

The code is:

ini_set("memory_limit", "2000M");


// Example. Zip all .html files in the current directory and send the file for Download.
$fileDir = './';

$fileTime = date("D, d M Y H:i:s T");

$zip = new Zip();
$zip->setComment("Example Zip file.\nCreated on " . date('l jS \of F Y h:i:s A'));
$zip->addFile("Hello World!", "hello.txt");

if ($handle = opendir($fileDir)) {
/* This is the correct way to loop over the directory. */
while (false !== ($file = readdir($handle))) {
if (strpos($file, ".jpg") !== false) {
$pathData = pathinfo($fileDir . $file);
$fileName = $pathData['filename'];

$zip->addFile(file_get_contents($fileDir . $file), $file, filectime($fileDir . $file));

if (ini_get('zlib.output_compression')) {
ini_set('zlib.output_compression', 'Off');

$zip->finalize(); // Not scrictly necessary, the next line will call it anyway.
$zipData = $zip->getZipData();
$length = strlen($zipData);

header('Pragma: public');
header("Last-Modified: " . $fileTime);
header("Expires: 0");
header("Accept-Ranges: bytes");
header("Connection: close");
header("Content-Type: application/zip");
header('Content-Disposition: attachment; filename="";' );
header("Content-Transfer-Encoding: binary");
header("Content-Length: ". $length);
echo $zipData;

The php.ini sets are:
ZLib Support enabled
Stream Wrapper support compress.zlib://
Stream Filter support zlib.inflate, zlib.deflate
Compiled Version 1.2.3
Linked Version 1.2.3

Directive Local Value Master Value
zlib.output_compression Off Off
zlib.output_compression_level -1 -1
zlib.output_handler no value no value


  2. Re: Error creating ZIP file bigger then 1Mb   Reply   Report abuse  
Asbjorn Grandt - 2011-01-28 14:52:27 - In reply to message 1 from matteo09
Can I get you to send me the problematic Zip (or a sample of the output from a 'safe' directory) at avg [at] ?

Or jave a look at the file in either a hex editor or wordpad, it must start with PK and end with null characters (0x00).

Also, I really ought to update the examples, the preferred method for delivering the Zip is


As this will avoid loading the entire Zip binary into memory.

Finalize is called automatically if the zip isn't already finalized.

Alternatively, if you really need to create archices that large, and they consists of multiple files (such as a large directory structure), I'd like to refer to my ZipStream class:

  3. Re: Error creating ZIP file bigger then 1Mb   Reply   Report abuse  
Asbjorn Grandt - 2011-01-28 15:05:21 - In reply to message 2 from Asbjorn Grandt

The preferred method of delivering a zip is