Reputation: 169
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.
Upvotes: 3
Views: 2005
Reputation: 25956
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");
Upvotes: 1