Answer the question
In order to leave comments, you need to log in
How do system() exec() and stuff work in PHP?
Good afternoon.
The question is the following - in php there are functions that execute system programs and display their output. There are many of them and in fact they work the same way. But here is one thing. Not a single installed program is executed through them. For example, I want to convert a file exec('enconv filepath');
This doesn't work. I try to do the same through the console, everything works fine.
Tried to prescribe the full path to the binary. /usr/bin/enconv
no difference. I also tried all the paths to the files that are possible. Nothing works.
I, of course, allowed the functions. I also tried to execute from the www-data user in the console - everything is done. And here through php the script does not want.
But, for example, calls
exec('echo 1');
exec('file -i filename');
Answer the question
In order to leave comments, you need to log in
I would like to give a solution if anyone is interested.
If we want to emulate the console in Php with all its responses in Php, we should use this construction.
$cmd = 'enconv /var/www/documents/xxx/\(1\)-1402322554-file -x utf8 -L russian';
$process = proc_open($cmd,
array(0 => array('pipe', 'r'), 1 => array('pipe', 'w'), 2 => array('pipe', 'w')), $pipes, NULL, NULL)) {
echo "<b>$cmd</b><br/>";
echo "OUTPUT:".stream_get_contents($pipes[1])."<br/>";
echo "ERRORS:".stream_get_contents($pipes[2])."<br/>";
echo "<br/>";
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question