Looking for help on executing pdftk from PHP

I am writing a script to fill out a PDF form. I'm using WAMP (Apache Version : 2.4.9, PHP Version : 5.5.12). I'm using a tool called pdftk v 1.44-win to fill in the PDF form. I am running Windows 8. I am using the exec command to run pdftk. I can run the command exactly as shown from the command line but it doesn't execute correctly from php. Since my initial return value is getting overwritten something is happening, but pdftk should return a numeric code, instead I'm getting nothing. I have verified that the SYSTEM process owns the files and has full control of the c:\wamp\www\bizcards directory.

I still think it may be a permissions problem. I originally wrote the portion of the script that mails the completed card on a different machine. When I try to load PHPMailer I get the following error on the new machine:

Warning: require(C:\wamp\www\styleguide\PHPMailer-master\PHPMailerAutoload.php): failed to open stream: Permission denied in C:\wamp\www\bizcards\getbizcard.php on line 69

The test code and output follow.

//Verbose Mode

echo "Running as user: ";
echo exec('whoami');
$filename = 'getbizcard.php';
$retval = 0;
echo "<br>Initial return value: ";
echo $retval;
$retval = exec("C:/Program Files (x86)/PDFtk/bin/pdftk bizcard.pdf fill_form c:/wamp/www/bizcards/bizcard_data.fdf output c:/wamp/www/bizcards/bizcard_data.fdf/mycard.pdf");
echo "<br>Final return value: ";
echo "***";
echo $retval;
echo "***";


Open in new window

Output is:

Running as user: nt authority\system
Initial return value: 0
Final return value: ******

Thanks in advance
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Try wrapping quotes around the binary, since the path has spaces in it:

$retval = exec("\"C:/Program Files (x86)/PDFtk/bin/pdftk\" bizcard.pdf fill_form c:/wamp/www/bizcards/bizcard_data.fdf output c:/wamp/www/bizcards/bizcard_data.fdf/mycard.pdf");
Also, the SYSTEM user probably isn't the one that needs permissions. If you're running this script via a web server, then the web server's process owner is the one that needs permissions to everything.
00daddyAuthor Commented:
Thanks gr8gonzo

I've had some success, I'm able to send pdf form data to my php script and generate a filled in PDF on the fly. The problem was in my code, I wasn't constructing my card object correctly. The reason I was getting null back from pdftk was that I did't use the verbose flag. So one problem solved. I'm in the final steps I just need to send the completed card by email. I'm using some code I had written previously that uses PHPMailer. The code worked fine on the machine I originally wrote it on, but after porting to another machine (Windows 8, 64-bit) I'm getting file permission erros when I try to include the PHPMailer class. The error is :

Warning: include_once(C:\wamp\www\styleguide\PHPMailer-master\class.phpmailer.php): failed to open stream: Permission denied in C:\wamp\www\bizcards\getbizcard.php on line 74

I have granted the SYSTEM account Administrative rights. I am using WAMP v2.5, Apache/2.4.9 (Win64) PHP/5.5.12 with PHPMailer v5.0.0 On a Windows 8-64bit system. The system account is the owner of the c:\wamp\www\bizcards directory. I don't seem to have an httpd process. I have one for wampserver, it is running as me, but I'm also an adminstrator. Any further help would be appreciated.

Mark Jefferson
Cloud Class® Course: SQL Server Core 2016

This course will introduce you to SQL Server Core 2016, as well as teach you about SSMS, data tools, installation, server configuration, using Management Studio, and writing and executing queries.

Try running procmon:

...and then run your test. It should show you all the filesystem activity (there will be a LOT of it - there's always something happening on Windows). Search for PHPMailer and you should find a line that shows you which process tried to access it. Then from there you can use task manager to see what user the process is running as.

That will be the user account that needs permissions, not SYSTEM.
00daddyAuthor Commented:
Hi gr8gonzo,

I'm still having the file permissions problem. When I try to include class.phpmailer.php the httpd.exe process gets denied access, httpd is being run by SYSTEM. I have given SYSTEM ownership of the file. In my Apache and PHP php.ini files I have added the directory to my include_path. I still get the following error:

Warning: include_once(C:\wamp\www\bizcards\class.phpmailer.php): failed to open stream: Permission
denied in C:\wamp\www\bizcards\getbizcard.php on line 74

The attached screenshots show my settings. Any help would be appreciated. This is starting to make me CRAZY !!!

Mark jefferson
No screenshot attached. Just for the sake of testing, try changing the file and folder permissions and add the "Everyone" account, with full permissions. Then test again and see if it works.

Did you change permissions on just the file before, or also on the folders in the path (wamp, www, and bizcards) ?

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
RobOwner (Aidellio)Commented:
I've requested that this question be deleted for the following reason:

Not enough information to confirm an answer.
The last comment I suggested should have opened up permissions wide enough to avoid the issue completely (although the OP would need to re-narrow the permissions afterwards for security purposes), so I'm assuming he simply got it working and stopped responding. If the issue was a permissions denied, then adding "Everyone" permissions was the hammer to kill the fly, but it should have definitely killed the fly.

I'd suggest accepting #40656852 as the answer and that any future readers of this should make sure you don't stop at wide-open permissions.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.