Fatal error: Class 'ZipArchive' not found in

04/03/2020 10:00:01

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.

Verified Answer (196 Votes)

10/06/2010 17:49:51

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).

196

Answer #2 (82 Votes)

05/06/2016 11:56:10

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

sudo apt-get install php7.0-zip

82

Answer #3 (38 Votes)

10/28/2016 17:10:29

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.

38
3
Hack Hex uses Stack Exchance API by the Stack Exchange Inc. to scrape questions/answers under Creative Commons license.