我有一个问题,我在Linux服务器上安装'Archive_Zip 0.1.1',但当我试图运行脚本创建zip文件时,它给出了致命的错误

致命错误:类ZipArchive没有在…

我把密码放哪了

$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;

但是它没有找到类文件。

请告诉我解决办法。我该怎么解决这个问题呢? 我还把php.ini文件放在脚本所在的文件夹中,但它不起作用。


当前回答

在CMS Typo3 ver.11.5.8中也是如此 当通过扩展管理器安装扩展时, 没关系,压缩扩展安装在cpanel。

原因是:在.htaccess中有:

AddType应用程序/x-httpd-php74 .php AddHandler应用程序/x-httpd-php74 .php

解决方案:通过以下方式更改上述内容: AddType application/x-httpd-alt-php74 .php .php7 .phtml

现在它对我起作用了。

其他回答

要出现ZipArchive类,PHP需要安装zip扩展。

有关安装说明(Linux和Windows),请参阅此页。

在Amazon ec2上,Ubuntu + nginx + php7,我有同样的问题,解决它使用:

Sudo apt-get install php7.0-zip

我在GCP上在应用引擎标准环境中部署wordpress时遇到了这个问题。这就解决了问题:

sudo apt-get install php7.2-zip

您需要检查PHP版本

如果php版本是5.6,你需要安装php5.7-zip

sudo apt-get install php5.6-zip

然后

sudo service apache2 restart

希望能有所帮助

Centos 6

或者任何基于rhel的口味

yum install php-pecl-zip

service httpd restart