wkhtmltoimage 和 PHP 调试

发布于 2024-11-14 06:52:37 字数 2164 浏览 5 评论 0 原文

我正在尝试使用 wkhtmltoimage 来抓取屏幕。它不起作用,但我不知道如何调试它。我联系了我的服务器管理员,他们说允许 exec 。这是我的目录结构:

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

screenshot.php 中的代码如下:

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 在 url“http://www.nasa.gov/”上调用函数 snapshot。

这是我得到的输出:

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

显然,我什至不确定错误来自哪里。可能是路径错误,或者输入以某种方式错误,但我不知道如何获得这些因素的任何输出。即使该函数似乎也没有通过我的数组返回任何输出行。

我该如何调试这个?我从哪里开始?是否有用于检查目录或文件执行情况的 PHP 函数?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

愚蠢的错误,我不得不使用根路径。 (例如 /home/...

是否有人也觉得 Web 开发中有一半的时间浪费在解决路径问题上?咕噜。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文