doubingjiu3199
2012-02-03 14:17
浏览 106
已采纳

在linux centos上通过php运行pdftk

I would like to run pdftk on my webserver. It's a Linux Centos with PHP 5.3.2.

When I connect it by commande line I do

pdftk --version

It's OK

pdftk A=p1-9.pdf cat A1 output p1.pdf

It's OK.

Now, I do this by php :

exec(pdftk A=p1-9.pdf cat A1 output p1.pdf)

It isn't OK. Why?? I search about the link of file, but it looks OK.

This doesn't work too :

exec(pdftk --version)

I install pdftk with this How do I install Pdftk on my server?

So what's wrong??

Thank for your help!

图片转代码服务由CSDN问答提供 功能建议

我想在我的网络服务器上运行pdftk。 它是一个带有PHP 5.3.2的Linux Centos。

当我通过命令行连接它时,我做

  pdftk --version 
    
 
 

没关系

  pdftk A = p1-9.pdf cat A1 output p1.pdf 
   
 
 

没关系。

现在,我通过php执行此操作:

  exec(  pdftk A = p1-9.pdf cat A1输出p1.pdf)
   
 
 

不行。 为什么?? 我搜索文件的链接,但看起来还不错。

这也不行:

  exec(pdftk  -  版本)
   
 
 

我用如何在我的服务器上安装Pdftk?

那有什么不对?

谢谢 你的帮助!

  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • douche3791 2012-02-03 14:54
    已采纳

    I've run into this issue before. Assuming that you're wrapping your commands string in quotes (as gioele noted), the issue may be that you need to set your path when running the system command. Try this:

    $command = "pdftk A=p1-9.pdf cat A1 output p1.pdf";
    system("PATH=\$PATH:/usr/bin/ && $command",$response);
    if ($response===FALSE){
       //there was an error, handle it
    }
    

    (I've added a little response handling there as well). If that doesn't work, check to see what path you should use (it will depend on where you installed PDFTK).

    I believe you can also get the same result by using putenv("PATH=" .[your path]); and I've used system() here, but exec() should be affected in the same way

    评论
    解决 无用
    打赏 举报

相关推荐 更多相似问题