Enable zip extension for PHP

I am trying to enable the .zip extension in PHP, but the function below returns false.

if (!extension_loaded('zip')) { return false; } 

How to enable .zip extension using php.ini?

Is it possible to enable the use of ini_set() ?

+7
source share
2 answers

If you really have the ZIP extension available on the server, you can use dl() to dynamically load (<5.3).

 if (!extension_loaded('zip')) { // Attempt to load the zip $prefix = (PHP_SHLIB_SUFFIX === 'dll') ? 'php_' : ''; dl($prefix . 'zip.' . PHP_SHLIB_SUFFIX); if (!extension_loaded('zip')) { // Couldn't load the ZIP module dynamically, either return false; } } 

If you use version higher than 5.3.0, you will not be able to use dl if it is not running on the command line or built into the web server.

This leaves your only option for modifying php.ini if you cannot recompile the module built into PHP. You cannot do this with ini_set , since it will only be applied at runtime, while all necessary modules will already be loaded by the PHP executable at startup.

+2
source

Use it

 if (!extension_loaded('zip')) { $prefix = (PHP_SHLIB_SUFFIX == 'dll') ? 'php_' : ''; dl($prefix . 'zip.' . PHP_SHLIB_SUFFIX); if (!extension_loaded('zip')) { return false; } } 
+1
source

All Articles