i'm trying to create a zip script based on what I've found here but I seem to be getting a Fatal error: Class 'ZipArchive' not found error on the new ZipArchive(); function.
Researching this it seems that this is usually due to the way PHP is compiled. I have a shared hosting account, so i've not configured any of this stuff...and I assume that I can't make any changes to the build. Out of interest I took a look in my phpinfo() and I found some things that looked associated:
PHP Version 5.2.6
BZip2 Support Enabled <--maybe not so relevant
ZLib Support enabled
Stream Wrapper support compress.zlib://
Stream Filter support zlib.inflate, zlib.deflate
Compiled Version 1.1.4
Linked Version 1.1.4
I'm not entirly sure if any of this means that I have the ability to create zips. For further info (although I don't think it's relivent) here's my script so far....this is untested mind you as I can't get pased this Class not found error.
$file = tempnam("tmp", "zip");
$zip = new ZipArchive();
$zip->open($file, ZipArchive::OVERWRITE);
//the string "file1" is the name we're assigning the file in the archive
$zip->addFile('show1.jpg', 'file1.jpg');
$zip->addFile('show2.jpg', 'file2.jpg');
$zip->addFile('show3.jpg', 'file3.jpg');
$zip->addFile('show4.jpg', 'file4.jpg');
$zip->addFile('show5.jpg', 'file5.jpg');
$zip->addFile('show6.jpg', 'file6.jpg');
// echo $zip->file(); //this sends the compressed archive to the output buffer instead of writing it to a file.
$zip->close();
header('Content-Type: application/zip');
header('Content-Length: ' . filesize($file));
header('Content-Disposition: attachment; filename="' . $file.'"');
readfile($file);
unlink($file);
So my question(s) really are:
Thanks in advance. Dan
ZipArchive is apparently not compiled into PHP by default. You need to either recompile it with the '--with-zip=' option or simply install it via PECL.
Here is the manual page explaining the different methods:
http://www.php.net/manual/en/zip.installation.php
While zlib is an important compression library, it sounds like you're missing the zip extension itself. It looks like you got your information from phpinfo
-- look for the exact words "zip extension." If you can't find them, you don't have it installed, and thus can not use the functions and methods provided by it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With