我有一个代码可以在测试服务器上正常工作,但在实时服务器上失败(由于 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 类的情况下使其工作?
编辑:我用过 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);
}
?>
效果很好。
最佳答案
检查两个系统上的 PHP 版本。
还要检查 php 是否使用 --enable-zip 配置选项编译
如果需要,请安装此模块。
检查:http://www.php.net/manual/en/zip.installation.php 有关如何安装的更多信息。
如果您想检查 php 是否具有正确的配置选项或加载的模块,您可以使用:
<?php
phpinfo();
?>
关于php - 无法实例化不存在的类 : ziparchive,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/6582672/