我有一个问题,我在Linux服务器上安装'Archive_Zip 0.1.1',但当我试图运行脚本创建zip文件时,它给出了致命的错误

致命错误:类ZipArchive没有在…

我把密码放哪了

$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;

但是它没有找到类文件。

请告诉我解决办法。我该怎么解决这个问题呢? 我还把php.ini文件放在脚本所在的文件夹中,但它不起作用。


当前回答

Centos 6

或者任何基于rhel的口味

yum install php-pecl-zip

service httpd restart

其他回答

我在这里没有看到它,所以我想补充的是,在Debian/Ubuntu上,你可能需要在安装相关包后启用扩展。所以:

sudo apt-get install php-zip
sudo phpenmod zip
sudo service apache2 restart

在Amazon ec2上,Ubuntu + nginx + php7,我有同样的问题,解决它使用:

Sudo apt-get install php7.0-zip

适用于Centos 7和Remi上的PHP 7.3

搜索zip扩展名:

$ yum search php73 | grep zip
php73-php-pecl-zip.x86_64 : A ZIP archive management extension

扩展名是php73-php-pecl-zip.x86_64。要在运行单一版本PHP的服务器上安装它,删除php73前缀:

$ sudo yum --enablerepo=remi-php73 install php-pecl-zip #for server running single PHP7.3 version
$ #sudo yum --enablerepo=remi-php73 install php73-php-pecl-zip # for server running multiple PHP versions

重启PHP:

$ sudo systemctl restart php-fpm

检查已安装的PHP扩展:

$ php -m
[PHP Modules]
apcu
bcmath
bz2
...
zip
zlib

您需要检查PHP版本

如果php版本是5.6,你需要安装php5.7-zip

sudo apt-get install php5.6-zip

然后

sudo service apache2 restart

希望能有所帮助

我有同样的问题与CentOS和cPanel安装服务器。我通过cPanel安装了zipArchive包,没有像预期的那样工作。 在尝试了这么多的修复建议后,每个地方都只有下面对我有用。

首先使用下面的命令找到正确的包的名称

yum search zip |grep -i php

然后使用下面的代码。

yum install your_zip_package_name_with_php_version

在我的情况下,安装zipArchive的正确代码是

yum install php-pecl-zip.x86_64

我从这个链接得到了解决方案。 我怎么能inslatt zipArchive在PHP 7.2与CentOS 7?

这个安装以某种方式启用了这个包,它也重新启动了影响服务,在上述代码执行完成后,zipArchive问题就消失了。