php 致命错误:找不到类“ZipArchive”
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3872555/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Fatal error: Class 'ZipArchive' not found in
提问by Parag Chaure
I have a problem that I install 'Archive_Zip 0.1.1' on Linux server, but when I try to run the script to create the zip file it gives the fatal error
我有一个问题,我在 Linux 服务器上安装了“Archive_Zip 0.1.1”,但是当我尝试运行脚本来创建 zip 文件时,它给出了致命错误
Fatal error: Class
ZipArchive
not found in ...
致命错误:
ZipArchive
在...中找不到类
where I put the code
我把代码放在哪里
$zip = new ZipArchive;
var_dump($zip);
$res = $zip->open($filename, ZipArchive::OVERWRITE);
if ($res !== TRUE) {
echo 'Error: Unable to create zip file';
exit;
}
if (is_file($src)) {
$zip->addFile($src);
} else {
// echo "<br>" . dirname(__FILE__) . $src;//'/install1';
if (!is_dir($src)) {
$zip->close();
@unlink($filename);
echo 'Error: File not found';
exit;
}
recurse_zip($src, $zip, $path_length);
}
$zip->close();
echo "<br>file name ".$filename;
but it doesn't find the class file.
但它没有找到类文件。
Please tell me the solution. What should I do to resolve the problem?
I also put php.ini
file to the folder where script is, but it does not work.
请告诉我解决方法。我应该怎么做才能解决问题?我也把php.ini
文件放在脚本所在的文件夹中,但它不起作用。
回答by Pekka
For the ZipArchive
classto be present, PHP needs to have the zip extensioninstalled.
要出现ZipArchive
该类,PHP 需要安装zip 扩展。
See this pagefor installation instructions (both Linux and Windows).
有关安装说明(Linux 和 Windows),请参阅此页面。
回答by star18bit
On Amazon ec2 with Ubuntu + nginx + php7, I had the same issues, solved it using:
在带有 Ubuntu + nginx + php7 的 Amazon ec2 上,我遇到了同样的问题,使用以下方法解决了它:
sudo apt-get install php7.0-zip
sudo apt-get install php7.0-zip
回答by Mubashar Abbas
On ubuntu desktop, I had to do.
在 ubuntu 桌面上,我不得不这样做。
sudo apt-get install php5.6-zip
This installed the library but I still kept on getting the same error, so I had to restart apache using:
这安装了库,但我仍然遇到相同的错误,所以我不得不使用以下命令重新启动 apache:
sudo service apache2 restart
and it worked.
它奏效了。
回答by Kalyan Halder Raaz
First of all, The solution for remote server:
首先,远程服务器的解决方案:
If you are using cpanelyou may have zip extension installed but not activate. You need to active it. For this case you need to go to cpanel > inside software section > click on PHP version. Then find zipand check it. Now save.
如果您使用的是cpanel,您可能安装了 zip 扩展但未激活。你需要激活它。对于这种情况,您需要转到cpanel > inside software 部分 > 单击 PHP version。然后找到zip并检查它。现在保存。
You should see like the image.
Refresh page. The error should disappear.
刷新页面。错误应该消失。
Note: If you dont found, contact server provider. They will install for you.
注意:如果没有找到,请联系服务器提供商。他们会为您安装。
回答by lorenzo-s
I'm not seeing it here, so I'd like to add that on Debian/Ubuntu you may need to enablethe extension after installing the relative package. So:
我在这里没有看到它,所以我想在 Debian/Ubuntu 上添加它,您可能需要在安装相关软件包后启用扩展。所以:
sudo apt-get install php-zip
sudo phpenmod zip
sudo service apache2 restart
回答by prosti
This worked
这有效
apt-get install php7.0-zip
and no need to restart php7.0-fpm
manually.
并且无需php7.0-fpm
手动重启。
Unpacking
php7.0-zip
(7.0.16-4+deb.sury.org~trusty+1
) ...
Processing triggers forphp7.0-fpm
(7.0.11-1+deb.sury.org~trusty+1
) ...php7.0-fpm
stop/waitingphp7.0-fpm
start/running, process 1572php7.0-fpm
stop/waitingphp7.0-fpm
start/running, process 1777
Setting upphp7.0-zip
(7.0.16-4+deb.sury.org~trusty+1
) ...
locale: Cannot setLC_ALL
to default locale: No such file or directoryCreating config file
/etc/php/7.0/mods-available/zip.ini
with new version
Processing triggers forphp7.0-fpm
(7.0.11-1+deb.sury.org~trusty+1
) ...php7.0-fpm
stop/waitingphp7.0-fpm
start/running, process 2354php7.0-fpm
stop/waitingphp7.0-fpm
start/running, process 2397
正在解包
php7.0-zip
(7.0.16-4+deb.sury.org~trusty+1
) ...
处理触发器php7.0-fpm
(7.0.11-1+deb.sury.org~trusty+1
) ...php7.0-fpm
停止/等待php7.0-fpm
启动/运行,进程 1572php7.0-fpm
停止/等待php7.0-fpm
启动/运行,进程 1777
设置php7.0-zip
(7.0.16-4+deb.sury.org~trusty+1
) ...
语言环境:无法设置LC_ALL
为默认语言环境:无此类文件或目录
/etc/php/7.0/mods-available/zip.ini
使用新版本创建配置文件
Processing triggers forphp7.0-fpm
(7.0.11-1+deb.sury.org~trusty+1
) ...php7.0-fpm
stop/waitingphp7.0-fpm
start/running, process 2354php7.0-fpm
stop/waitingphp7.0-fpm
start/running, process 2397
回答by temo
If you have WHM available it is easier.
如果你有可用的WHM,那就更容易了。
Log in to WHM.
登录WHM。
Go to EasyApache4 (or whatever version u have) under Softwaretab.
转到“软件”选项卡下的EasyApache4(或您拥有的任何版本)。
Under Currently Installed Packages click Customize.
在当前安装的软件包下单击自定义。
Go to PHP Extensions, in search type "zip" (without quotes),
转到PHP Extensions,在搜索类型“ zip”(不带引号)中,
you should see 3 modules
你应该看到 3 个模块
check all of them,
检查所有这些,
click blue button few times to finish the process.
单击蓝色按钮几次以完成该过程。
This worked for me. Thankfully I've WHM available.
这对我有用。谢天谢地,我有 WHM 可用。
回答by antonD
I had the same issue with CentOSand cPanelinstalled server. I installed zipArchive package via cPanel and didn't worked as expected. After trying with so many fixes suggested each and everywhere just the below worked for me.
我在安装CentOS和cPanel 的服务器上遇到了同样的问题。我通过 cPanel 安装了 zipArchive 包,但没有按预期工作。在尝试了如此多的修复之后,每个地方都提出了以下建议对我有用。
First find the name for the correct package with the below command
首先使用以下命令找到正确包的名称
yum search zip |grep -i php
Then use the below code.
然后使用下面的代码。
yum install your_zip_package_name_with_php_version
In my case correct code to install zipArchive was
在我的情况下,安装 zipArchive 的正确代码是
yum install php-pecl-zip.x86_64
I had the solution from this link. How can I inslatt zipArchive on PHP 7.2 with CentOS 7?
我从这个链接得到了解决方案。 如何使用 CentOS 7 在 PHP 7.2 上安装 zipArchive?
And this installation somehow enabled that package too and it also restarted the effecting services and after the completion of the execution of the above code zipArchive issue was gone.
这个安装也以某种方式启用了该包,它还重新启动了影响服务,并且在执行完上述代码后 zipArchive 问题消失了。
回答by zzapper
Centos 6
Centos 6
yum install php-pecl-zip
service httpd restart
回答by Jeremy
You also need to compile PHP with zip support. The manual says the following:
您还需要使用 zip 支持编译 PHP。手册说如下:
In order to use these functions you must compile PHP with zip support by using the --enable-zip configure option.
为了使用这些函数,您必须使用 --enable-zip 配置选项编译支持 zip 的 PHP。
It's not enough to simply install the correct extensions on the server. Have a look at the installation instructions link Pekka posted earlier. My answer is just a clarification of his.
仅仅在服务器上安装正确的扩展是不够的。查看 Pekka 之前发布的安装说明链接。我的回答只是对他的澄清。