简体   繁体   English

WkHtmlToPdf通过shell_exec()传递变量

[英]WkHtmlToPdf Passing Variables via shell_exec()

Here is a sample of my script 这是我的脚本示例

$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) ;

The problem i seem to be having is with the $command, basically when it runs wkHTMLtoPDF it runs it via a Command Line, and &variable= bit causes the script to error as via command line & is another command, my question is how do i get the variables to be passed correctly so that the script this then sends to, will be able to use $_GET variables that i require for the script to then work ? 我似乎遇到的问题是使用$命令,基本上当它运行wkHTMLtoPDF时它通过命令行运行它,并且&variable = bit导致脚本错误,因为通过命令行&是另一个命令,我的问题是我怎么做获取要正确传递的变量,以便然后发送到的脚本能够使用我需要的$ _GET变量来运行吗?

I have done a bit of looking up and found something along the lines of using $argv 1 ; 我已经做了一些查找并发现了一些使用$ argv 1的内容 ;

Replacing $_GET to make it work from command line 替换$ _GET以使其从命令行运行

However i cannot seem to find a reference that closely matches my needs. 但是,我似乎无法找到一个与我的需求密切相关的参考。

Change this: 改变这个:

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

To this: 对此:

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

Actually wkhtmltopdf accepts and passes POST data to the server-side page being printed/exported to pdf. 实际上,wkhtmltopdf接受并将POST数据传递到正在打印/导出为pdf的服务器端页面。

All you need is --post fieldName value . 您只需要--post fieldName value

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

You can have as many as that in the command to pass as many post parameters as you want 您可以在命令中使用尽可能多的帖子参数

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM