I am trying to enable the .zip extension in PHP, but the function below returns false.
if (!extension_loaded('zip')) {
return false;
}
How do I enable the .zip extension with out using php.ini?
Is it possible to enable using ini_set()
?
Provided that you actually have the ZIP extension available on the server, you could use dl()
to dynamically load it (<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're using a version above 5.3.0, you won't be able to use dl
unless it's running on the command line or embedded into a web server.
That leaves your only option to be modification of the php.ini
if you can't recompile with the module built-in to PHP. You can't do this using ini_set
, as that will only be applied at runtime whilst all of the required modules will already have been loaded by the PHP executable at startup.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With