0
votes

Possible Duplicate:
Executing linux commands with PHP

I have a PHP file that creates an .xfdf file I am wondering if PHP has a way of executing a command like you would type into the terminal window? I have to run the following command when after the .xfdf file is created to generate the .pdf file

pdftk /var/www/pdf/TimeCard.pdf fill_form /var/www/pdf/results/Brandon_01_23_13.xfdf output /var/www/pdf/results/testNew.pdf flatten

The command would need to be able to accept a PHP variable so its customized for the user. Is there an easy way to do this?

4
Just check the related questions on your bottom-right side of this page!Shiplu Mokaddim

4 Answers

4
votes

Yes, you can use exec(), pcntl_exec(), system().

$command = 'pdftk /var/www/pdf/TimeCard.pdf fill_form /var/www/pdf/results/Brandon_01_23_13.xfdf output /var/www/pdf/results/testNew.pdf flatten';
exec($command);

Be very careful when using these commands, they are very useful/powerful, but because of this a hacker could potentially gain access to your whole server through it (depending on permissions, but it's more than enough to compromise your site).

If you need to send user uploaded file names/text, check them to the blood (for example check if the file path is in the proper place, and not ../../../something.pdf, check MIME types and extensions).

2
votes
2
votes

Depending on your exact requirements, you can use exec(), system() or shell_exec()

1
votes

Use the system() or eval() functions.

But make sure the user can not inject arbitrary commands!