无法实例化不存在的类:zipcarchive


Cannot instantiate non-existent class: ziparchive

我有一个代码在测试服务器上正常工作,但在实时服务器上失败(由于PHP版本(。

我得到这个错误:

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

代码为:

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

如何在没有ZipArchive类的情况下使其工作


编辑:我用过强大的谷歌:

<?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);
}
?>

效果很好。

检查两个系统上的PHP版本。还检查php是否使用--enablezip配置选项编译

如果需要,请安装此模块。

检查:http://www.php.net/manual/en/zip.installation.php有关如何安装的详细信息。

如果你想检查php是否有正确的配置选项或加载的模块,你可以使用:

<?php
phpinfo();
?>

也许您只是没有在服务器端php.ini中启用ZipArchive模块?

编辑:也许你只是忘了括号?尝试$zip=新ZipArchive((;