419
419

Reputation: 179

Cannot instantiate non-existent class: ziparchive

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.

Upvotes: 3

Views: 2229

Answers (2)

Mor&#242;Switie
Mor&#242;Switie

Reputation: 1516

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();

?>

Upvotes: 2

Christian Smorra
Christian Smorra

Reputation: 1754

maybe you just have not enabled the ZipArchive module in your serverside php.ini?

Edit: maybe you just forgot the brackets? Try $zip = new ZipArchive();

Upvotes: 0

Related Questions