2011-07-22 193 views
7

我如何通过PHP执行这两个命令行:通过php执行命令行?

wkhtmltopdf www.google.com gg.pdf

&

oofice -headless -nologo -pt杯PDF my.doc

他们都返回一个PDF文件并下载到我的主目录。

我想知道从我的html页面通过php执行这些命令的方式。

谢谢。

+0

参见[这](http://stackoverflow.com/questions/566248/cant-execute-php-script-using-php-exec) –

回答

15

你应该看看本手册的System program execution部分:PHP提供了几个功能,可以用来启动外部命令/程序,包括:

  • exec() - 它可以存储的输出返回,作为一个字符串,所述命令
  • system()的输出 - - 在一个阵列
  • shell_exec()命令呼应的命令的输出
+0

感谢帕斯卡的回答, – XS07

+0

谢谢您的回答, 但是,我尝试了命令 echo shell_exec('wkhtmltopdf --version - '); 它会输出版本信息。但当我运行 echo shell_exec('wkhtmltopdf www.google.com my.pdf'); 它什么也没有, wkhtmltopdf是一个包的URL:www.google.com转换为PDF格式,并保存my.pdf到相同的难度。 如何处理通过php导致pdf的命令行? – XS07

2

要从php(在Linux中)创建PDF,您必须使用包装。

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

exec($cmd);