php 找不到 PHPExcel ZipArchive

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/25176999/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 17:42:22  来源:igfitidea点击:

PHPExcel ZipArchive not found

phpphpexcel

提问by whiteestee

I've just downloaded PHPExcel package and I tried to import an Excel spreadsheet, but all I get is an error ZipArchive not found. I work on Windows, but server is on Linux. I checked php.inito see if php_zip is disabled, but it wasn't even there.

我刚刚下载了 PHPExcel 包,我试图导入一个 Excel 电子表格,但我得到的只是一个错误ZipArchive not found。我在 Windows 上工作,但服务器在 Linux 上。我检查php.ini了 php_zip 是否被禁用,但它甚至不存在。

I tried installing it with PECL: $ pecl install zip

我尝试用 PECL 安装它: $ pecl install zip

No releases availble for package "pecl.php.net/zip" Cannot initialize 'channel://pecl.php.net/zip', invalid or missing package file Package "channel://pecl.php.net/zip" is not valid install failed

No releases availble for package "pecl.php.net/zip" Cannot initialize 'channel://pecl.php.net/zip', invalid or missing package file Package "channel://pecl.php.net/zip" is not valid install failed

And also pear install zip-1.10.2.tgzbut recieved pretty much the same message.

而且也pear install zip-1.10.2.tgz收到了几乎相同的消息。

I don't have root permission to the server, maybe that's the case? Anyways, could you help me with this?

我没有服务器的 root 权限,也许是这样?无论如何,你能帮我解决这个问题吗?

回答by Mark Baker

Certain spreadsheet file formats, such as OfficeOpenXML used as the default format by Excel 2007 and above, require ZipArchive. In most recent versions of PHP, ZipArchive is always available, but prior to PHP 5.3 it needed to be manually installed as a PHP extension.

某些电子表格文件格式(例如 Excel 2007 及更高版本用作默认格式的 OfficeOpenXML)需要 ZipArchive。在最新版本的 PHP 中,ZipArchive 始终可用,但在 PHP 5.3 之前,它需要作为 PHP 扩展手动安装。

As @briosheje says If you don't have ZipArchive installed/enabled for your PHP, then you can use

正如@briosheje 所说,如果您没有为 PHP 安装/启用 ZipArchive,那么您可以使用

PHPExcel_Settings::setZipClass(PHPExcel_Settings::PCLZIP);

PCLZip is included in the PHPExcel distribution as an alternative to PHP's built-in ZipArchive class, though it is quite a bit slower. Enabling PCLZip allows you to work with zip-based spreadsheet formats even without ZipArchive.

PCLZip 包含在 PHPExcel 发行版中,作为 PHP 内置 ZipArchive 类的替代品,但它的速度要慢一些。启用 PCLZip 允许您使用基于 zip 的电子表格格式,即使没有 ZipArchive。

However, when we first bundled PCLZip (originally in PHPExcel 1.7.6), it was only an option when writing zip-based formats, not when reading them. We changed that in PHPExcel 1.8.0, so enabling PCLZip now allows you to read zip-based formats as well as writing them.

然而,当我们第一次捆绑 PCLZip(最初在 PHPExcel 1.7.6 中)时,它只是编写基于 zip 的格式时的一个选项,而不是读取它们时。我们在 PHPExcel 1.8.0 中更改了这一点,因此现在启用 PCLZip 允许您读取和写入基于 zip 的格式。

The PHPEXcel Reader documentation details the different spreadsheet formats, and explains which ones are zip-based.

PHPEXcel Reader 文档详细介绍了不同的电子表格格式,并解释了哪些是基于 zip 的。

回答by Kent Aguilar

In my case I have PHP 5.4
Upon using PHPExcel, I encountered this exception.

在我的情况下,我有 PHP 5.4
在使用 PHPExcel 时,我遇到了这个异常。

FatalErrorException in Excel2007.php line 94: Class 'ZipArchive' not found

Solved it by appending this line on PHPExcel/Reader/Excel2007.php

通过在PHPExcel/Reader/Excel2007.php上附加这一行来解决它

PHPExcel_Settings::setZipClass(PHPExcel_Settings::PCLZIP);

before invoking the getZipClass method.

在调用 getZipClass 方法之前。

$zipClass = PHPExcel_Settings::getZipClass();

回答by Stas Panyukov

You have to install extension for php called like php-zipand zip program on your linux machine.

你必须在你的 linux 机器上安装名为php-zip和 zip 程序的php扩展。

回答by Raghavendra BK

I found simple solution:

我找到了简单的解决方案:

 1. login to your cpanel
 2. go to software > select PHP version
 3. select PHP version 7.0 and click set as current button
 4. check zip checkbox
 5. click save

Now you refresh your site to download excel file

现在您刷新站点以下载 excel 文件

回答by Shafiq

If you are using cpanel you may have zip extension installed but not activate. You need to active it. For this case you need to go to cpanel > inside software section > click on PHP version. Then find zip and check it. Now save. Enable zip extension

如果您使用的是 cpanel,您可能安装了 zip 扩展但未激活。你需要激活它。对于这种情况,您需要转到 cpanel > 内部软件部分 > 单击 PHP 版本。然后找到zip并检查它。现在保存。 启用 zip 扩展

Refresh your application page.

刷新您的应用程序页面。

回答by Jean claude Nshimirimana

The easy way is to insert : PHPExcel_Settings::setZipClass(PHPExcel_Settings::PCLZIP); in your script just before calling $objWriter->save();

简单的方法是PHPExcel_Settings::setZipClass(PHPExcel_Settings::PCLZIP); 在调用之前在脚本中 插入 : $objWriter->save();

This worked for me.

这对我有用。

regards!

问候!