wkhtmltoimage and PHP debug
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("./wkhtmltoima开发者_JAVA百科ge/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?
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.
精彩评论