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


当前回答

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.

其他回答

在ubuntu桌面上,我必须这么做。

sudo apt-get install php5.6-zip

这安装了库,但我仍然得到相同的错误,所以我必须重新启动apache使用:

sudo service apache2 restart

这招奏效了。

您需要检查PHP版本

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

sudo apt-get install php5.6-zip

然后

sudo service apache2 restart

希望能有所帮助

这个工作

apt-get install php7.0-zip

并且不需要手动重启php7.0-fpm。

Unpacking php7.0-zip (7.0.16-4+deb.sury.org~trusty+1) ... Processing triggers for php7.0-fpm (7.0.11-1+deb.sury.org~trusty+1) ... php7.0-fpm stop/waiting php7.0-fpm start/running, process 1572 php7.0-fpm stop/waiting php7.0-fpm start/running, process 1777 Setting up php7.0-zip (7.0.16-4+deb.sury.org~trusty+1) ... locale: Cannot set LC_ALL to default locale: No such file or directory Creating config file /etc/php/7.0/mods-available/zip.ini with new version Processing triggers for php7.0-fpm (7.0.11-1+deb.sury.org~trusty+1) ... php7.0-fpm stop/waiting php7.0-fpm start/running, process 2354 php7.0-fpm stop/waiting php7.0-fpm start/running, process 2397

您还需要编译带有zip支持的PHP。手册内容如下:

为了使用这些函数,您必须使用——enable-zip configure选项来编译支持zip的PHP。

仅仅在服务器上安装正确的扩展是不够的。看看Pekka之前发布的安装说明链接。我的回答只是对他的澄清。

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

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