Use wkhtmltoimage in php

php

Solution

I'm guessing that `passthru` is disabled in the `php.ini` file used for the web server for security reasons. Try executing the following code:

function passthru_enabled() {
    $disabled = explode(', ', ini_get('disable_functions'));
    return !in_array('exec', $disabled);
}
if (passthru_enabled()) {
    echo "passthru is enabled";
} else {
    echo "passthru is disabled";
}

If it is disabled, there's really nothing you can do unless you can edit the php.ini file.

Edit: Also, make sure you enable error reporting in your code, which should also display some sort of warning if you try to use a disabled function. Put this in your code:

error_reporting(-1);
ini_set('display_errors', 'On');

Edit:

If `passthru` is enabled, then the only reason I can think of that a command should execute correctly by the command line and not PHP is because it is not being passed correctly to the command line. Try adding quotes around the arguments using escapeshellarg.

$url = escapeshellarg('http://codante.org/linux-php-screenshot');
$command = "./wkhtmltoimage --width 164 --height 105 --quality 100 --zoom 0.2 $url file/test.jpg";

You may also want to take advantage of the second parameter of `passthru`, which returns the exit status of the command. A non-zero value indicates that there was an error.

passthru($command, $status);
if ($status != 0) {
    echo "There was an error executing the command. Died with exit code: $status";
}

For a list of these exit codes to help you debug what is happening see Exit codes with special meanings

Problem

When I use wkhtmltoimage in terminal,it works well. But it has some problem when used in php. It is the problem: The php code: ``` <?php $command = './wkhtmltoimage --width 164 --height 105 --quality 100 --zoom 0.2 http://www.google.com file/test.jpg'; ob_start(); passthru($command); $content = ob_get_clean(); echo $command; echo $content; ?> ``` It works.And when I try the same command in terminal,it works well too. But when I try other links,it can't work well. ``` <?php $command = './wkhtmltoimage --width 164 --height 105 --quality 100 --zoom 0.2 http://codante.org/linux-php-screenshot file/test.jpg'; ob_start(); passthru($command); $content = ob_get_clean(); echo $command; echo $content; ?> ``` It does work.But when I try same command in terminal.It works! Plz help me.

Original source