Run command line via php?

How can I execute these two commands with php:

wkhtmltopdf www.google.com gg.pdf

&

oofice -headless -nologo -pt cup-pdf my.doc

both of them return a PDF file and are uploaded to my home directory.

I want to know how to execute this command from my html page via php.

Thanks.

+7
source share
2 answers

You should familiarize yourself with the System program section: PHP provides several functions that can run external commands / programs, including:

  • exec() - which can store the output of a command in an array
  • shell_exec() - which returns the output of the command as a string
  • system() - which displays the output of the command
+15
source

To create a pdf file from php (on Linux) you must use a wrapper.

 $cmd = '/usr/bin/xvfb-run --server-args="-screen 0, 1920x1080x24" /usr/bin/wkhtmltopdf http://google.com /tmp/google.pdf'; exec($cmd); 
+2
source

All Articles