Understanding exec()

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
cczernia
Forum Newbie
Posts: 20
Joined: Tue May 16, 2006 2:00 pm
Location: San Diego, CA

Understanding exec()

Post 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.
desmi
Forum Commoner
Posts: 64
Joined: Sun Jun 15, 2008 4:55 am

Re: Understanding exec()

Post 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?
User avatar
cczernia
Forum Newbie
Posts: 20
Joined: Tue May 16, 2006 2:00 pm
Location: San Diego, CA

Re: Understanding exec()

Post 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.
desmi
Forum Commoner
Posts: 64
Joined: Sun Jun 15, 2008 4:55 am

Re: Understanding exec()

Post by desmi »

Does your apache error.log say anything?
desmi
Forum Commoner
Posts: 64
Joined: Sun Jun 15, 2008 4:55 am

Re: Understanding exec()

Post 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?
User avatar
cczernia
Forum Newbie
Posts: 20
Joined: Tue May 16, 2006 2:00 pm
Location: San Diego, CA

Re: Understanding exec()

Post by cczernia »

Might there be something I have to change to php.ini or something?
desmi
Forum Commoner
Posts: 64
Joined: Sun Jun 15, 2008 4:55 am

Re: Understanding exec()

Post 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 :)
User avatar
andre_c
Forum Contributor
Posts: 412
Joined: Sun Feb 29, 2004 6:49 pm
Location: Salt Lake City, Utah

Re: Understanding exec()

Post 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');
Post Reply