The Exec command does not work as expected

I am trying to run a CLI command with a PHP script:

in particular, I want to use this command convert a.png a.tifto convert an image to tiff.

When I run this command from the CLI, it works as expected, but if I run with a PHP script with the following code, it does not create any tiff image in my folder:

$exec = "convert a.png a.tif";
exec($exec,$yaks,$err);
echo "<pre>";
print_r($yaks);
echo "$err";
echo "</pre>";

Moreover, it is $yaksempty, but $err- 127.

I am not an expert, why does this not work as expected?

Regards

UPDATE

I used this command instead $exec = "convert 4.png 4.tif 2>&1";, and I got back[0] => sh: convert: command not found

It seems strange to me, because I can use it from the CLI!

FINAL UPDATE

Thanks a lot guys!

$exec = "/usr/local/bin/convert a.png a.tif";

This team solved the problem! You are wonderful.

+2
3

fullpath "" .

err 127 -

+2

, 'convert' PATH, PHP. , . /opt/local/bin/convert .

PATH, PHP ( , ).

+2

The PHP script probably does not know where to find these things that you are talking about in the command exec. When you run this from the command line, the shell will look for them in the directory in which you are currently located; but when you start it from PHP, it probably uses the PHP directory by default, not the specific directory where your files are located. So write the full path.

+1
source

Source: https://habr.com/ru/post/1545034/


All Articles