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:
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 have upgrade php version or zip extension is not there
So you have to install it .
1) Open terminal
2) sudo apt-get install php7.0-zip
3) sudo service apache2 restart
You could try dl("zip.so");
as last resort. But that extension is rarely built as external module. You might be able to find it downloadable somewhere, or even compile it by hand from the PHP sources or http://pecl.php.net/package/zip using pecl build
Otherwise you will have to look for an alternative. http://pear.php.net/package/Archive_Zip comes to mind.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.