1

I'm trying to use wkhtmltoimage in PHP to grab a screen. It's not working, but I don't know how to debug it. I contacted my server admins and they said that exec was allowed. Here's my directory structure:

-index.php
-lib/
  -screenshot.php
  -wkhtmltoimage/
     -wkhtmltoimage-i386
     -wkhtmltoimage-amd64

The code in screenshot.php is the following:

function screenshot($url, $save_path, $zoom = 0.5, $width = 500)
{
    $zoom = escapeshellarg($zoom);
    $width = escapeshellarg($width);
    $url = escapeshellarg($url);
    $save_path = escapeshellarg($shell_path);

    print_r(scandir("lib/wkhtmltoimage"));

    $output = array();

    echo exec("./lib/wkhtmltoimage/wkhtmltoimage-i386 --enable-plugins --zoom $zoom --width $width $url test.png", $output);
    echo exec("lib/wkhtmltoimage/wkhtmltoimage-i386 --enable-plugins --zoom $zoom --width $width $url test.png", $output);
    echo exec("./wkhtmltoimage/wkhtmltoimage-i386 --enable-plugins --zoom $zoom --width $width $url test.png", $output);
    echo exec("wkhtmltoimage/wkhtmltoimage-i386 --enable-plugins --zoom $zoom --width $width $url test.png", $output);
    echo exec("./lib/wkhtmltoimage/wkhtmltoimage-amd64 --enable-plugins --zoom $zoom --width $width $url test.png", $output);
    echo exec("lib/wkhtmltoimage/wkhtmltoimage-amd64 --enable-plugins --zoom $zoom --width $width $url test.png", $output);
    echo exec("./wkhtmltoimage/wkhtmltoimage-amd64 --enable-plugins --zoom $zoom --width $width $url test.png", $output);
    echo exec("wkhtmltoimage/wkhtmltoimage-amd64 --enable-plugins --zoom $zoom --width $width $url test.png", $output);

    print_r($output);
    die();
}

index.php calls the function screenshot on url "http://www.nasa.gov/".

Here's the output I get:

Array
(
    [0] => .
    [1] => ..
    [2] => wkhtmltoimage-amd64
    [3] => wkhtmltoimage-i386
)
Array
(
)

Visibly, I'm not even sure where the error comes from. It could be that the path is wrong, or that the input is wrong somehow, but I don't know how to get any output on these factors. Even the function doesn't seem to return any line of output through my array.

How can I debug this? Where do I start? Are there PHP functions for checking directories, or file execution?

1
  • Not sure if this will help, but I had to redirect stderror to stdout: $blah = shell_exec("$cmd 2>&1"); That might help you out. Commented Jun 16, 2011 at 17:24

1 Answer 1

3

Stupid mistake, I had to use the root path. (e.g. /home/...)

Does anyone also feel like half of the time in web development is wasted in solving path problems? Grrr.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.