如何在 CentOS 上的 PHP 5.3 中激活 ZipArchive 类

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4319359/
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 12:39:21  来源:igfitidea点击:

How-to activate the ZipArchive class in PHP 5.3 on CentOS

phpcentosinstallationziparchive

提问by Savageman

I read on the documentationI should only compile PHP 5.3.3 with "--enable-zip" parameter, but this doesn't work. I did this but class_exists('ZipArchive')always return false. What should I do next?

我阅读了文档,我应该只使用“--enable-zip”参数编译 PHP 5.3.3,但这不起作用。我这样做了,但class_exists('ZipArchive')总是返回false。我接下来该怎么做?

回答by Andreas Wong

Have you tried installing ZipArchive using pecl?

您是否尝试过使用 pecl 安装 ZipArchive?

$ pecl install zip

then add extension=zip.so to your php.ini

然后将 extension=zip.so 添加到您的 php.ini

回答by Jason

Make sure that the Zip class is being loaded by your server by,

确保您的服务器正在加载 Zip 类,

  1. Write a quick phpinfo(); script and check if Zip is enabled; and
  2. If it isn't, you can check the /etc/php.d/zip.ini file to make sure that the zip.so file is being loaded when PHP kicks off.
  3. As you can see heremake sure you are using the class_exists function correctly for your version of PHP.
  1. 写一个快速的 phpinfo(); 脚本并检查是否启用了 Zip;和
  2. 如果不是,您可以检查 /etc/php.d/zip.ini 文件以确保在 PHP 启动时正在加载 zip.so 文件。
  3. 正如您在此处看到的,请确保为您的 PHP 版本正确使用 class_exists 函数。

[ >= PHP 5.3]

[ >= PHP 5.3]

If you are checking if a class exists that is in a specific namespace then you have to pass in the full path to the class:

如果要检查特定命名空间中是否存在类,则必须传入该类的完整路径:

echo (class_exists("com::richardsumilang::common::MyClass")) ? "Yes" : "No";

echo (class_exists("com::richardsumilang::common::MyClass")) ? “是”:“否”;

Hope that helps.

希望有帮助。

回答by Gregory Hanis

pecl install zip: compilation terminated. make: *** [php_zip.lo] Error 1 ERROR: `make' failed

pecl install zip: 编译终止。make: *** [php_zip.lo] 错误 1 ​​错误:`make' 失败