wkhtmltopdf - URL 中的空格


wkhtmltopdf - Spaces in URL

使用 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);
?>

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

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

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

$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,而不是例如 ./config/database.php ,并且$_GET['img']也必须进行消毒。