0

这是我的脚本示例

$clientid = $_POST['clientid']; 
$from_day = $_POST['stat_from_day'];
$from_month = $_POST['stat_from_month'];
$from_year = $_POST['stat_from_year'];
$to_day = $_POST['stat_to_day'];
$to_month = $_POST['stat_to_month'];
$to_year = $_POST['stat_to_year'];

$from_date_string = $from_day . ' ' . $from_month . ' ' . $from_year ; 
$to_date_string = $to_day . ' ' . $to_month . ' ' . $to_year ; 

$baseurl = "http://www.test.com/";
$part1 = "?Search=" . $clientid . " from_day=" . $from_day . " from_month=" . $from_month . " from_year=" . $from_year ;
$part2 = " to_day=" . $to_day . " to_month=" . $to_month . " to_year=" . $to_year ;

$time = mktime();
$formatted_time = date("d_M_Y", $time);

$command = "xvfb-run -a /usr/bin/wkhtmltopdf --ignore-load-errors";
$url = $baseurl . $part1 . $part2 ;

$html = file_get_contents($url);

$output_dir = '/var/www/stats/pdf/';
$output = $clientid . '_Search_Export_' . $formatted_time . rand(10000, 99999) . '.pdf';

$generate = shell_exec($command . ' ' . $url . ' ' . $output_dir . $output) ;

我似乎遇到的问题是 $command,基本上当它运行 wkHTMLtoPDF 时,它通过命令行运行它,并且 &variable= 位会导致脚本出错,因为通过命令行 & 是另一个命令,我的问题是我该怎么做获取要正确传递的变量,以便随后发送到的脚本能够使用我需要的 $_GET 变量,然后脚本才能工作?

我做了一些查找,发现了一些类似于使用 $argv 1的东西;

替换 $_GET 以使其从命令行工作

但是,我似乎找不到与我的需求非常匹配的参考。

4

2 回答 2

1

实际上 wkhtmltopdf 接受 POST 数据并将其传递到正在打印/导出为 pdf 的服务器端页面。

你只需要--post fieldName value.

xvfb-run -a /usr/bin/wkhtmltopdf --ignore-load-errors --post username blablabla --post bla2 answer2

您可以在命令中包含尽可能多的参数来传递任意数量的post参数

于 2014-12-05T11:47:16.757 回答
1

改变这个:

$url = $baseurl . $part1 . $part2 ;

对此:

$url = "\" . $baseurl . $part1 . $part2 . "\";
于 2013-08-20T19:39:09.577 回答