views:

663

answers:

3

I would like to run ffmpeg from PHP for video encoding purposes.

I was thinking of using the exec or passthru commands. However, I have been warned that enabling these functions is a security risk. In the words of my support staff:

The directive 'disable_functions' is used to disable any functions that allow the execution of system commands. This is for more security of the server. These PHP functions can be used to crack the server if not used properly.

I'm guessing that if exec is enabled, then someone could (possibly) execute an arbitrary unix command. Does anyone know of a secure way to run ffmpeg from PHP?

By the way, I'm on a dedicated server. Thanks ahead of time!

+5  A: 

exec does not itself present a security risk any more than you logging into a secure terminal would.

Think of it this way, if you were to list the contents of a directory like so

exec( 'ls /foo/bar' );

it would not matter what your user sent to your php script, it would only ever list the directory specified.

As long as you are careful to sanitize any inputs from the user, and refrain from outputing sensitive information you should be ok.

Use the following methods to sanatize input for before running it on the command line:

Josiah
Thanks! So I guess I'm safe since I am generating my own inputs to the ffmpeg command.
Venkat D.
@Josiah: I think you meant exec(); not eval().http://us2.php.net/manual/en/function.exec.php
Andrew
@Andrew: Thanks, I have amended the answer.
Josiah
A: 

can i execute ffmpeg without de command "exec" ? thanks. rafael.

rafael
A: 

you can try using an ffmpeg-php library... found here: http://sourceforge.net/projects/ffmpeg-php/

Mike