Is it possible to set a location of a library extension within a Php file

StackOverflow https://stackoverflow.com/questions/3067992

  •  28-09-2019
  •  | 
  •  

문제

I want to load an extension within a Php file as I don't have access to the php.ini file.

I tried:

ini_set('extension','php_gd2.dll');

With the file in the same directory as the Php page but it did not work.

Must it always be done with in php.ini or can it be done like the above?

도움이 되었습니까?

해결책

if (!extension_loaded('php_gd2')) {
    if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') {
        dl('php_gd2.dll');
    } else {
        dl('php_gd2.so');
    }
}

But note that it won't work with all SAPIs; and is explicitly disabled when running in safe mode or PHP is built with zts support.

다른 팁

Extensions are generally loaded at runtime, which is in many server cases start of http server. So this is rather impossible UPDATE - I was wrong, see Mark Baker answer, and really unneeded. On shared hosting environments you will certainly not have access to such feature (because it is way too much risk) and when you have access to php.ini... Why not to use it?

UPDATE: If you're not even having access to php.ini there's no way anyone will give you the access to such dangerous feature as custom extensions (unless the admin's bad at it). The extension has access to the internals of PHP and can really mess with the server.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top