Fatal error: Class 'ZipArchive' not found in

↘锁芯ラ 提交于 2019-11-26 09:28:47

问题


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

Fatal error: Class ZipArchive not found in ...

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.


回答1:


For the ZipArchive class to be present, PHP needs to have the zip extension installed.

See this page for installation instructions (both Linux and Windows).




回答2:


On Amazon ec2 with Ubuntu + nginx + php7, I had the same issues, solved it using:

sudo apt-get install php7.0-zip




回答3:


On ubuntu desktop, I had to do.

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:

sudo service apache2 restart

and it worked.




回答4:


I'm not seeing it here, so I'd like to add that on Debian/Ubuntu you may need to enable the extension after installing the relative package. So:

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



回答5:


First of all, The solution for remote server:

If you are using cpanel you 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 zip and check it. Now save.

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.




回答6:


This worked

apt-get install php7.0-zip

and no need to restart php7.0-fpm manually.

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




回答7:


You also need to compile PHP with zip support. The manual says the following:

In order to use these functions you must compile PHP with zip support by using the --enable-zip configure option.

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.




回答8:


If you have WHM available it is easier.

Log in to WHM.

Go to EasyApache 4 (or whatever version u have) under Software tab.

Under Currently Installed Packages click Customize.

Go to PHP Extensions, in search type "zip" (without quotes),

you should see 3 modules

check all of them,

click blue button few times to finish the process.

This worked for me. Thankfully I've WHM available.




回答9:


PHP 5.2.0 and later

Linux systems

In order to use these functions you must compile PHP with zip support by using the --enable-zip configure option.

Windows

Windows users need to enable php_zip.dll inside of php.ini in order to use these functions.




回答10:


I had the same issue with CentOS and cPanel installed 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.

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

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?

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.




回答11:


Centos 6

yum install php-pecl-zip

service httpd restart



回答12:


I had the same issue and it had solved using two command lines:

sudo apt install php-zip

then reboot your web server, for Apache

sudo service apache2 restart




回答13:


I faced this issue on GCP while deploying wordpress in the App Engine Standard environment. This solved it :

sudo apt-get install php7.2-zip



回答14:


1) You should require your file with ZipArchive file.

require 'path/to/file/ZipArchive.php';

2) Or use __autoload method of class. In PHP 5 it is a greate method __autoload().

function __autoload($class_name) {
    require_once $class_name . '.php';
}

$obj  = new MyClass1(); // creating an object without require.

http://www.php.net/manual/en/language.oop5.autoload.php



来源:https://stackoverflow.com/questions/3872555/fatal-error-class-ziparchive-not-found-in

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!