Enable the 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 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 (!extension_loaded('zip'))
{ 
    $prefix = (PHP_SHLIB_SUFFIX == 'dll') ? 'php_' : '';
    dl($prefix . 'zip.' . PHP_SHLIB_SUFFIX);
    if (!extension_loaded('zip')) 
    {
       return false;
    }
}
链接地址: http://www.djcxy.com/p/12284.html

上一篇: 自动播放下一个类实例

下一篇: 启用PHP的zip扩展