doulan8152 2017-04-03 15:01
浏览 42
已采纳

PDFTk适用于本地但不在私有服务器上工作

I have private server CentOS 6 and I have installed pdftk program to generate pdf files. When I connect with SSH client, I can run pdftk program successfully. But I couldn't in php with exec() function.

I have a very simple php file as shown below. This is only to test if pdftk is working or not. When I ran this file on my localhost with xampp, it generates the file but when I tried on my private server, not gives error and not generates the file. I am not expert and expecting any help from you. Thanks in advance.

PHP CODE:

<?php
exec("pdftk form.pdf output private.pdf");

The error look like this:

Array ( [0] => Error: Failed to open output file:
  [1] => collated.pdf [2] => No output created.) 

Note: I have tried this code on putty ssh client and works perfectly.

  • 写回答

1条回答 默认 最新

  • doujiong3146 2017-04-03 20:24
    关注

    The error is: Array ( [0] => Error: Failed to open output file: [1] => collated.pdf [2] => No output created. . same exec code on putty works fine.

    The difference you can spot is in the user running the code. In case of PuTTY, you are logged in as a different user than the user who is running your script when accessed from web. Since you are creating a new file, the user needs a write access to the directory, where you are. This is generally a bad idea to allow to write that user to the directory, where your scripts are so it is a good idea to create a new directory (such as export), where the apache user will have access to write:

    mkdir export
    chown apache:apache export
    chmod 755 export
    

    and modify your script to write a file into that directory:

    exec("pdftk form.pdf output export/private.pdf");
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么