Fatal error: class "ZipArchive" not found in

I have a problem installing "Archive_Zip 0.1.1" on a Linux server, but when I try to run a script to create a zip file, it gives a fatal error " Fatal error: class" ZipArchive "was 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 he did not find the class file.

Please tell me the solution, what should I do to solve the problem. I also put the php.ini file in the folder where the script is, but it does not work.

+151
php zip ziparchive
06 Oct 2018-10-06
source share
9 answers

For the ZipArchive class to be present, PHP must have a zip extension .

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

+181
Oct 06 2018-10-06
source share
— -

On Amazon ec2 with Ubuntu + nginx + php7, I had the same problems that were resolved with:

sudo apt-get install php7.0-zip

+77
May 6 '16 at 6:56 a.m.
source share

On the ubuntu desktop I had to do.

 sudo apt-get install php5.6-zip 

This installed the library, but I still kept getting the same error, so I had to restart apache using:

 sudo service apache2 restart 

and it worked.

+35
Oct 28 '16 at 12:10
source share

I do not see this here, so I would like to add that in 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 
+14
Oct. 16 '17 at 6:54 on
source share

First of all, the solution for the remote server:

If you are using cpanel , you may have a zip extension but not activated. You need to activate it. For this case, you need to go to the cpanel section > inside the software section> click on the PHP version . Then find the zip and check it out. Now save.

You should see as an image. enter image description here

Refresh the page. The error should disappear.

Note. If you have not found, contact your service provider. They will be installed for you.

+11
Nov 17 '17 at 2:39 on
source share

It 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 
+5
Mar 13 '17 at 19:22
source share

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

To use these functions, you must compile PHP with zip support using the --enable-zip configure option.

It is not enough to simply install the correct extensions on the server. Take a look at the Pekka installation link posted earlier. My answer is just an explanation of it.

+4
Oct 06 2018-10-06
source share

PHP 5.2.0 and later

Linux systems

To use these functions, you must compile PHP with zip support using the -enable-zip configure option.

Window

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

+3
Jul 01 '13 at 11:39 on
source share

1) You must require your file with the ZipArchive file.

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

2) Or use the __autoload method of the class. In PHP 5, this is a friendly __autoload () method.

 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

-10
Oct 06 '10 at 12:52
source share



All Articles