Page 1 of 1

Understanding exec()

Posted: Fri Aug 15, 2008 10:51 am
by cczernia
I recently installed ImageMagick on my server. I have a php script that uploads an image and I wanted to create a thumbnail. You can do this from the command line in linux using "mogrify". I tried using the exec function with mogrify but nothing happens.

Code: Select all

exec ('mogrify -thumbnail 100x100 *.jpg')
Does exec only use certain commands or should it launch any command? If it can launch any command what am I doing wrong because in the same script I also tested exec with "ls" and it works fine. Thanks in advance.

Re: Understanding exec()

Posted: Fri Aug 15, 2008 11:06 am
by desmi
Not very sure about this, but have you tried this one? :

Code: Select all

shell_exec('string');
And is your mogrify usable that way? does it need ./ or something before the command?

Re: Understanding exec()

Posted: Fri Aug 15, 2008 11:16 am
by cczernia
I just tried shell_exec() and it did not do anything. From the command line all I have to do is type "mogrify". If you just type mogrify it will list the pararmeters that go along with it. So, I even tried an "echo exec('mogrify');" and that didn't work.

Re: Understanding exec()

Posted: Fri Aug 15, 2008 11:21 am
by desmi
Does your apache error.log say anything?

Re: Understanding exec()

Posted: Fri Aug 15, 2008 11:47 am
by desmi
I just tried command:

Code: Select all

echo shell_exec('mogrify');
Echoes the same as the shell does when run.. I wonder if there's some problem with your server/configuration?

Re: Understanding exec()

Posted: Fri Aug 15, 2008 12:07 pm
by cczernia
Might there be something I have to change to php.ini or something?

Re: Understanding exec()

Posted: Fri Aug 15, 2008 12:15 pm
by desmi
umm, i have completely default debian "etch", apache2, php4 and php5, mysql and proftpd on my server, i haven't changed anything at php.ini/apache.conf or httpd.conf..

it might be permission problem too ?

I hope someone who understands linux better, helps you out here, while waiting, i'll try my best :)

Re: Understanding exec()

Posted: Fri Aug 15, 2008 8:55 pm
by andre_c
It might be that it is throwing an error but to stderr. Try redirecting stderr to stdout:
<code>

Code: Select all

exec('mogrify -thumbnail 100x100 *.jpg 2>&1');