25May/058
More on ZIP File Creation
I did some more testing with the code I posted yesterday and found it isn't 100% compatible with some unzip programs. Works with unix unzip, Mac OS X default tool, WinZip, WinRAR but annoyingly not with the default XP zip folder thing.
The problem seem to be 4 rogue bytes that gets inserted somewhere. So back to Google, eventually I found a much better library at PHP Concept Library Zip. It works more or less the same, except you must pass it files to add instead of just data in variables, either works for me.
Some sample code:
require ("incl/pclzip.lib.php");
$zipfile = new PclZip('zipfile.zip');
$v_list = $zipfile->create('incl/pclzip.lib.php');
if ($v_list == 0) {
die ("Error: " . $zipfile->errorInfo(true));
}
header("Content-type: application/octet-stream");
header("Content-disposition: attachment; filename=zipfile.zip");
readfile("zipfile.zip");
This one works with every unzip tool I've tried, Windows, OS X, command line unzip etc. It also has decent error reporting etc.


January 20th, 2006 - 21:44
Hey, i was wondering how you make it save to file, i can’t seem to find an example anywhere that will allow me to save the created zip to a specific directory on my web server
January 20th, 2006 - 21:54
In the example above the file will be saved in ‘zipfile.zip’ you can put any path in there.
February 13th, 2006 - 14:34
Have you tried to extract a file that is not in the same directory of the php script?
Something like
$zipfile = new PclZip(‘test\zipfile.zip’)
I was not able to extract it!!
May 1st, 2006 - 20:58
I have been trying to use the example code above, but I get an error:
Error: PCLZIP_ERR_READ_OPEN_FAIL (-2) : Unable to open archive ‘zipfile.zip’ in wb mode.
I have tried changing the filename to something that doesn’t exist, and that gives a different error, so I know that php is able to access the file that I want to zip.
Are there some settings in php that have to be enabled to make this execute?
Thanks
August 24th, 2006 - 06:49
Hi … i can convert one single file to zip format using this code . How can use this code for converting a folder to zip foramt.
December 11th, 2006 - 16:36
I got this to work great… until I tried to include an 80Mb file.. and it all fell down.
has anyone had any luck with compiling ‘large’ zip files…?
June 11th, 2007 - 23:18
Both Windows XP and Winrar are unable to read the zips this thing generates. Says they are invalid format. Booo.
June 20th, 2008 - 18:14
I was just wondering if you could tell me how to stop the open box from popping up. Essentially I want to just zip the file and echo that it has been zipped. Thanks,