0

使用 wkhtmltopdf 时,当 URL 包含%20.

通过命令行在本地执行相同的命令时,这不是问题。

有没有办法在它上线后让它工作?

到目前为止,我的代码是:

<?php
$url = $_GET['url'];    // Website URL to Create Image
$name = $_GET['img'];   // Output Image Name
$command = "/usr/local/bin/wkhtmltoimage --no-images --crop-w 580";
$dir_img = "images/";     // Image files will be saved here
$ex_cmd = "$command $url " . $dir_img . $name;
$output = shell_exec($ex_cmd);
?>

除非%20URL 中有一个,否则这工作正常。

我需要截屏的页面必须其 URL中包含,%20因此不幸的是,删除它的功能不是解决方案。

4

1 回答 1

2

你必须逃避你的论点,否则你的代码中有一个巨大的安全漏洞:

$url = escapeshellarg($_GET['url']);    // Website URL to Create Image
$name = escapeshellarg($_GET['img']);   // Output Image Name
$command = "/usr/local/bin/wkhtmltoimage --no-images --crop-w 580";
$dir_img = "images/";     // Image files will be saved here
$ex_cmd = "$command $url " . $dir_img . $name;
$output = shell_exec($ex_cmd);

这只是为了让您入门,您还必须检查$_GET['url']是 url,而不是 eg ./config/database.php,并且也$_GET['img']必须进行清理。

于 2015-01-14T13:44:19.957 回答