Question

I'm currently using the following two command to generate client statements populated from mysql tables. There are three variables, client_id, date_start. date_end

wget -O mypage.html "http://mypage.php?client_id=var1&date_start=var2&date_end=var3"

wkhtmltopdf-i386 --margin-left 5mm --margin-right 5mm mypage.html mypage.pdf

This works perfectly and produces usable statements. What I would now like to do is implement a web page using three drop down menus to select each variable rather than directly typing it into linux command line. The user would select the client, date start and date end, using the web interface then click "Print Report". This would send the variables to the command line and run the two lines displayed above.

I know how to make forms but I cant figure out how to pass the variables to the command line and run these 2 lines. I'm sure its simple if anyone can help?

Many thanks

Was it helpful?

Solution

//assumes, you have extracted $clientid, $startdate, $enddate from your $_REQUEST and validated them

$command="wget -O mypage.html \"http://mypage.php?client_id=$clientid&date_start=$startdate2&date_end=$enddate\"";
exec($command, $output, $status);
if ($status!=0) die("wget failed");


$command="htmltopdf-i386 --margin-left 5mm --margin-right 5mm mypage.html mypage";
exec($command, $output, $status);
if ($status!=0) die("htmltopdf failed");

Pitfalls: You should use /path/to/wget and /path/to/htmltopdf-i386 to make sure, your PATH is OK

OTHER TIPS

http://php.net/manual/en/function.system.php is the answer to your needs :)

It even gets the output for you (in case of error messages etc, very usefull)

to run multiple commands use && eg: system("ls && exit");

I have the same issue, when I try to run it from the command line it works like a charm, but, if I try to execute it via browser it doesn't work.

I have even tested with the command line the same piece of code in a test.php file. In command line it generates the pdf file but in browser it doesn't.

You have assigned your question as answered. I can't see where is the right answer...

Maybe you are having the same problem solved in this question exec() problem with long command in PHP

Look at Edit 3

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top