0

I am working on a script that requires ImageMagick and I need to check for it as well as enable it if it isn't enabled. I understand that I can enable extension=imagick.so in my php.ini file. However, not everyone using the script will have access to that option. So I need to check on the fly and enable as I said earlier. I know that the PHP dl() method is deprecated, and I have tried several other things in an attempt to output the enabled extensions and have failed. Is there a method possible to enable the ImageMagick module from within a PHP script/file?

Here was my last attempt:

<?php
    echo "<pre>";
    print_r(get_loaded_extensions());
    echo "</pre>";

    if (!extension_loaded('imagick')) {
        echo "<br><br><hr><br>";
        echo "ADDING ImageMagick:<br><br>";
        ini_set("extension", 'imagick.so');

        echo "<pre>";
        print_r(get_loaded_extensions());
        echo "<pre>";
    }
}

* UPDATE *

I just tried to create a php.ini fileand save it to a location in the 'system' folder but that too seems to have failed. ;)

<?php
    echo "<pre>";
    print_r(get_loaded_extensions());
    echo "</pre>";
    // Example loading an extension based on OS
    if (!extension_loaded('imagick')) {
        echo "<br><br><hr><br>";
        echo "ADDING ImageMagick:<br><br>";
        $content = "extension=imagick.so";
        $fp = fopen("/my-root-path-behind-public-here/php.ini","wb");
        fwrite($fp,$content);
        fclose($fp);
        echo "<pre>";
        print_r(get_loaded_extensions());
        echo "<pre>";
    }
W3bGuy
  • 735
  • 7
  • 20
  • Check out the following link, http://stackoverflow.com/questions/18123754/load-extension-dynamically – JustBaron Feb 18 '17 at 20:40
  • There HAS to be some way of doing this though. What about creating a php.ini file with the enabled flag and dropping it in a writable folder? – W3bGuy Feb 18 '17 at 20:42
  • I may be wrong, but I think you would still need to re-start the webserver for the changes to take effect. – JustBaron Feb 18 '17 at 20:46
  • testing now. I'll report back. :) – W3bGuy Feb 18 '17 at 20:46
  • That didn't seem to work either. I figured that would be the case, but wanted to at least try. – W3bGuy Feb 18 '17 at 21:05
  • Why don't you just enable the option? – JustBaron Feb 19 '17 at 08:43
  • Like I said in the OP, not everyone using the script will have that ability when installing. I ended up just writing a checker file though that runs through and tests for imagemagick and/or gd. I think I am going to just let them know in the checker if they are able to use it or not that way. If neither is installed then they will need to either enable one or contact their hosting provider to enable one. This means I will have to either write both ways of handling the image creation or limit it to one or the other. My understanding is that most hosts allow GD by default but not IM. – W3bGuy Feb 19 '17 at 14:51

0 Answers0