Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot instantiate non-existent class: ziparchive

Tags:

php

I've a code that works correctly on test server but fails on live one (due to PHP version).

I'm getting this error:

Fatal error: Cannot instantiate non-existent class: ziparchive in /home/sites/www.example.com/web/zip.php on line 123

and the code is:

$zip = new ZipArchive;
$zip->open($_FILES['uploadedfile']['tmp_name']);
$zip->extractTo('unzipped/' . $id . '/');
$zip->close();

How to make it working without ZipArchive class being available?


Edit: I've used Mighty Google:

<?php
$zip = zip_open("zip.zip");
if ($zip) {
  while ($zip_entry = zip_read($zip)) {
    $fp = fopen("zip/".zip_entry_name($zip_entry), "w");
    if (zip_entry_open($zip, $zip_entry, "r")) {
      $buf = zip_entry_read($zip_entry, zip_entry_filesize($zip_entry));
      fwrite($fp,"$buf");
      zip_entry_close($zip_entry);
      fclose($fp);
    }
  }
  zip_close($zip);
}
?>

Works great.

like image 654
419 Avatar asked May 09 '26 05:05

419


1 Answers

Check the PHP version on both systems. also check if php was compiled with the --enable-zip configure option

Install this module if needed.

check: http://www.php.net/manual/en/zip.installation.php for more information on how to install.

If you want to check if php has the right configure options or loaded modules you can use:

<?php

phpinfo();

?>
like image 144
Cecil Zorg Avatar answered May 11 '26 18:05

Cecil Zorg



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!