php exec() returning empty value

2019-07-21 10:56发布

Currently my goal is to use see the output of PHP exec() but getting an empty value. Am using firephp (firebug extension) logging and can't figure out why it is empty.

full code here: https://github.com/MattMcFarland/ninja-forms-uploads-custom/blob/dev/uploads-custom.php

Form here: http://www.hvac-hacks.com/?page_id=1383&preview=true&form_id=96

            exec('mogrify -auto-orient -verbose -format jpg '.$dir."/".$user_file_name,$ouput);
            fb($output);
            curl_exec('mogrify -auto-orient -verbose -format jpg '.$dir."/".$user_file_name,$output);
            fb($output);
            $output = shell_exec('mogrify -auto-orient -verbose -format jpg '.$dir."/".$user_file_name);
            fb($output);

Currently console shows empty for each exec method I'm using. Really not sure what to do, am at a complete loss.

The console IS working as well, as it shows other fb(); stuff. The exec commands are showing an empty line with the number 3 in front of it, indicating empty return 3 times.

Any ideas?

标签: php exec mogrify
2条回答
我想做一个坏孩纸
2楼-- · 2019-07-21 11:27

exec will be empty if it can not find the command you are trying to run. You need to tell php where it can find mogrify by using putenv. In my case mogrify's path is /opt/local/bin. So the following code would work, you will just need to use the correct path for your environment.

putenv("PATH=/opt/local/bin");
exec('mogrify -auto-orient -verbose -format jpg '.$dir."/".$user_file_name,$ouput);
fb($output);
curl_exec('mogrify -auto-orient -verbose -format jpg '.$dir."/".$user_file_name,$output);
fb($output);
$output = shell_exec('mogrify -auto-orient -verbose -format jpg '.$dir."/".$user_file_name);
fb($output);

I hope that helps.

查看更多
戒情不戒烟
3楼-- · 2019-07-21 11:39

Problem was a permissions issue. the user was not allowed to use BASH.

Had to change bin/false to bin/bash in /etc/passwd for apache user.

In hindsight might be better to just add bin/mogrify

查看更多
登录 后发表回答