Login   Register  
PHP Classes
elePHPant
Icontem

Error creating ZIP file bigger then 1Mb

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us

      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??
Messages:3
Author:matteo09
Date:2011-01-28 14:30:03
Update:2011-01-28 15:05:21
 

  1. Error creating ZIP file bigger then 1Mb   Reply  
Picture of matteo09
matteo09
2011-01-28 14:30:03
Hello,
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:

<?php
ini_set("memory_limit", "2000M");

error_reporting(E_ALL);

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

include_once("Zip.php");
$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="ZipExample.zip";' );
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

Thank's
Matteo

  2. Re: Error creating ZIP file bigger then 1Mb   Reply  
Picture of Asbjorn Grandt
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] grandt.com ?

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

$zip->setZipFile("ZipExample2.zip");

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:
http://www.phpclasses.org/package/6616


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

The preferred method of delivering a zip is

$zip->sendZip("ZipExample.zip");