[英]PHP Zip Creating Class ZipArchive Not Found Error
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(); 我正在尝试根据我在这里找到的内容创建一个zip脚本,但我似乎遇到致命错误:新的ZipArchive()上没有找到类'ZipArchive'错误; function.
功能。
Researching this it seems that this is usually due to the way PHP is compiled. 研究这似乎通常是由于PHP的编译方式。 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:
出于兴趣,我看了一下我的phpinfo(),我找到了一些看似相关的东西:
PHP Version 5.2.6 PHP版本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. ZipArchive默认情况下显然没有编译成PHP。 You need to either recompile it with the '--with-zip=' option or simply install it via PECL.
您需要使用'--with-zip ='选项重新编译它,或者只需通过PECL安装它。
Here is the manual page explaining the different methods: 以下是解释不同方法的手册页:
http://www.php.net/manual/en/zip.installation.php 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 . 虽然zlib是一个重要的压缩库,但听起来你错过了zip扩展本身 。 It looks like you got your information from
phpinfo
-- look for the exact words "zip extension." 看起来你从
phpinfo
获得了你的信息 - 寻找确切的单词“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 如果你有升级php版本或zip扩展不存在
So you have to install it . 所以你必须安装它。
1) Open terminal 1)打开终端
2) sudo apt-get install php7.0-zip 2)sudo apt-get install php7.0-zip
3) sudo service apache2 restart 3)sudo service apache2 restart
You could try dl("zip.so");
你可以试试
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
您可能能够在某处找到它可下载,甚至可以从PHP源代码手动编译或使用
pecl build
http://pecl.php.net/package/zip
Otherwise you will have to look for an alternative. 否则你将不得不寻找替代方案。 http://pear.php.net/package/Archive_Zip comes to mind.
想到http://pear.php.net/package/Archive_Zip 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.