php exec() returning empty value

守給你的承諾、 提交于 2020-01-04 06:48:31

问题


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?


回答1:


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




回答2:


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.



来源:https://stackoverflow.com/questions/18797512/php-exec-returning-empty-value

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!