我有一个问题,我在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文件放在脚本所在的文件夹中,但它不起作用。


当前回答

对于PHP 7.x

sudo apt-get install php-zip

对于PHP 5.x

sudo apt-get install php5.x-zip
// (for example sudo apt-get install php5.6-zip)

然后重新启动Apache服务器

sudo service apache2 restart

其他回答

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

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

要出现ZipArchive类,PHP需要安装zip扩展。

有关安装说明(Linux和Windows),请参阅此页。

对于PHP 7.4 >,默认情况下不再存在ZipArchive,您需要安装和配置它。

我强烈建议你使用一个可以包含在你的项目中的库,比如https://github.com/zanysoft/laravel-zip 这个库只是原生ZipArchive的包装器

CPanel [ Sharing Hosting ]
To fix this issue or error use the below steps:-

Error Details:-
/=========================================================================
An uncaught Exception was encountered
Type: Error

Message: Class 'ZipArchive' not found

Filename: /home/b2bvniowy1go/public_html/system/libraries/PHPExcel/Reader/Excel2007.php

Line Number: 85

Backtrace:

File: /home/b2bvniowy1go/public_html/dashboard/controllers/Brand_price.php

============================================================================ /

cPanel Version [ 94.0 (build 19) ]
Solution:-  Do this changes to your remote server:  Cpanel > Select PHP version section > extensions tab. Then find zip and check it. Now save.

如果你有WHM可用,那就更容易了。

登录WHM。

在“软件”选项卡下进入EasyApache 4(或任何你拥有的版本)。

在“当前安装的包”下单击“自定义”。

进入PHP扩展,搜索“zip”(不带引号),

您应该看到3个模块

都检查一下,

点击几次蓝色按钮来完成这个过程。

这对我很管用。 谢天谢地,我有WHM可用。