简体   繁体   English

找不到“ZipArchive”类

[英]Class 'ZipArchive' not found

What I want to realize我想实现的

I will use PhpSpreadsheet in a PHP web application development, I am trying to configure PHP Zip extension necessary for PhpSpreadsheet to be enabled on the server.我将在 PHP Web 应用程序开发中使用PhpSpreadsheet ,我正在尝试配置 PHPSpreadsheet 所需的 PHP Zip 扩展,以便在服务器上启用。 I tried two methods, but I could not set it well, so I would like you to tell me the solution and other things to check.两种方法都试过,都设置不好,请各位大神告知解决方法和其他检查事项。

1st method I tried我试过的第一种方法

Execute the following at the terminal在终端执行以下操作

# yum install php71-php-pecl-zip.x86_64
# cp /etc/opt/remi/php71/php.d/40-zip.ini /etc/php.d/40-zip.ini
# systemctl stop httpd.service
# systemctl start httpd.service

When executing processing using PhpSpreadsheet from the Web browser, an error occurred从 Web 浏览器使用 PhpSpreadsheet 执行处理时,发生错误

/vendor/phpoffice/phpspreadsheet/src/PhpSpreadsheet/Reader/Xlsx.php: 71
Class 'ZipArchive' not found

I confirmed that the Zip extension is enabled at the terminal, but I do not know the cause.我确认在终端启用了 Zip 扩展,但我不知道原因。

# php --info
Additional. Ini files parsed =>
·
·
/etc/php.d/40-zip.ini
·
·
zip

Zip => enabled
Zip version => 1.15.2
Libzip headers version => 1.3.2
Libzip library version => 1.5.1

zlib

ZLib Support => enabled
Stream Wrapper => compress.zlib: / /
Stream Filter => zlib.inflate, zlib.deflate
Compiled Version => 1.2.7
Linked Version => 1.2.7

Directive => Local Value => Master Value
zlib.output_compression => Off => Off
zlib.output_compression_level => -1 => -1
zlib.output_handler => no value => no value

# php vendor / phpoffice / phpspreadsheet / samples / index.php
Requirement check:
PHP 5.6.0 ... passed
PHP extension XML ... passed
PHP extension xmlwriter ... passed
PHP extension mbstring ... passed
PHP extension ZipArchive ... passed
PHP extension GD (optional) ... passed
PHP extension dom (optional) ... passed

2nd method I tried我试过的第二种方法

After canceling the setting of 1st (uninstall package, delete the copied file) Execute the following at the terminal取消1st的设置后(卸载包,删除复制的文件)在终端执行以下

# yum install php71-php-devel.x86_64
# yum install zlib-devel.x86_64
# pecl install zip

The following error occurred in the third command第三个命令出现如下错误

# pecl install zip
No releases available for package "pecl.php.net/zip"
install failed

Due to the error above, downloading the file and executing phpize will not proceed with an error again ...由于上面的错误,下载文件并执行phpize不会再继续报错...

# wget http://pecl.php.net/get/zip-1.15.2.tgz
# phpize
Can not find PHP headers in /usr/include/php
The php-devel package is required for use of this command.

I did not understand why errors occurred in pecl install zip and phpize .我不明白为什么pecl install zipphpize发生错误。

Additional information (FW / tool version, etc.)附加信息(固件/工具版本等)

OS: Red Hat Enterprise Linux Server release 7.4 (Maipo)操作系统:Red Hat Enterprise Linux Server 7.4 (Maipo)

PHP: 7.1.14 PHP:7.1.14

first, run this command首先,运行这个命令

sudo yum install php-zip

after change php.ini file更改 php.ini 文件后

extension=zip.so

now run this command.现在运行这个命令。

sudo service httpd restart
sudo service php-fpm restart

it's working for me in cent os on amazon server.它在亚马逊服务器上的 cent os 中为我工作。

For the ZipArchive class to be present, PHP needs to have the zip extension installed.要出现ZipArchive类,PHP 需要安装zip 扩展

See this page for installation instructions (both Linux and Windows).有关安装说明(Linux 和 Windows),请参阅此页面

Solution for CentOS 8: CentOS 8 的解决方案:

yum install php74-libzip.x86_64
yum install php-pecl-zip

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM