Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
php exec command
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Portage & Programming
View previous topic :: View next topic  
Author Message
kermitthefrog917
Tux's lil' helper
Tux's lil' helper


Joined: 08 May 2005
Posts: 106

PostPosted: Tue Oct 24, 2006 6:07 am    Post subject: php exec command Reply with quote

I am trying to put a line into my php script.

I have the following

exec('convert $itempicture -resize 100x150 $itemthumbnail');

and nothing is happening... wheres the error?
Back to top
View user's profile Send private message
zoni
n00b
n00b


Joined: 04 Sep 2006
Posts: 60
Location: The Netherlands

PostPosted: Tue Oct 24, 2006 9:33 am    Post subject: Reply with quote

For a start, check you php and apache logs, see if anything unusual shows up there.
Back to top
View user's profile Send private message
gen2fox
Guru
Guru


Joined: 25 May 2004
Posts: 544

PostPosted: Tue Oct 24, 2006 9:52 am    Post subject: Reply with quote

What are the exit status and output of exec?
Code:
exec('convert $itempicture -resize 100x150 $itemthumbnail', $output, $exit_status);
print join('<br />', $output);
print 'Exit status: ' . $exit_status;

_________________
python>>> q="'";s='q="%c";s=%c%s%c;print s%%(q,q,s,q)';print s%(q,q,s,q)
blog
Back to top
View user's profile Send private message
skunk
l33t
l33t


Joined: 28 May 2003
Posts: 646
Location: granada, spain

PostPosted: Tue Oct 24, 2006 12:12 pm    Post subject: Re: php exec command Reply with quote

kermitthefrog917 wrote:
exec('convert $itempicture -resize 100x150 $itemthumbnail');

use double quotes else $itempicture and $itemthumbnail won't be evaluated:
Code:
exec("convert $itempicture -resize 100x150 $itemthumbnail");
Back to top
View user's profile Send private message
Errtu
Apprentice
Apprentice


Joined: 12 Nov 2002
Posts: 155
Location: Brazil

PostPosted: Tue Oct 24, 2006 12:23 pm    Post subject: Reply with quote

I've also experienced that things work better if you execute exec() with a variable:

Code:
$comnd = "put your command in here";
exec($comnd);
Back to top
View user's profile Send private message
Aurisor
Guru
Guru


Joined: 20 Sep 2003
Posts: 361
Location: Boston MA

PostPosted: Tue Oct 24, 2006 3:10 pm    Post subject: Re: php exec command Reply with quote

kermitthefrog917 wrote:
I am trying to put a line into my php script.

I have the following

exec('convert $itempicture -resize 100x150 $itemthumbnail');

and nothing is happening... wheres the error?


If you want to capture the output you have to pass a second argument as follows:

exec("convert $itempicture -resize 100x150 $itemthumbnail",$output);

and then go:

print_r($output);

And you should see your output.

Also, for debugging purposes, I'd reccomend you use passthru....saves you the trouble of capturing the output and printing it out.

http://us2.php.net/manual/en/function.passthru.php

You also might want to enclose your output in pre tags to make sure the formatting comes out right.

IAAPPP (I am a professional PHP programmer =) )


Last edited by Aurisor on Tue Oct 24, 2006 3:12 pm; edited 1 time in total
Back to top
View user's profile Send private message
Aurisor
Guru
Guru


Joined: 20 Sep 2003
Posts: 361
Location: Boston MA

PostPosted: Tue Oct 24, 2006 3:10 pm    Post subject: Reply with quote

Errtu wrote:
I've also experienced that things work better if you execute exec() with a variable:

Code:
$comnd = "put your command in here";
exec($comnd);


That may keep you more organized but unless there is a SERIOUS bug in your version of PHP that should never affect the output.
Back to top
View user's profile Send private message
kermitthefrog917
Tux's lil' helper
Tux's lil' helper


Joined: 08 May 2005
Posts: 106

PostPosted: Tue Oct 24, 2006 3:14 pm    Post subject: Reply with quote

The command convert wasn't in the default path, I needed to specify the full path and it worked perfectly.
Back to top
View user's profile Send private message
gen2fox
Guru
Guru


Joined: 25 May 2004
Posts: 544

PostPosted: Tue Oct 24, 2006 3:59 pm    Post subject: Re: php exec command Reply with quote

skunk wrote:
kermitthefrog917 wrote:
exec('convert $itempicture -resize 100x150 $itemthumbnail');

use double quotes else $itempicture and $itemthumbnail won't be evaluated:
Code:
exec("convert $itempicture -resize 100x150 $itemthumbnail");


Good catch!

Also, are the variables taken from user input? If so then please make sure they are properly sanitized, otherwise an attacker may some serious harm to your server.

Take a look at http://www.php.net/manual/en/function.escapeshellcmd.php
_________________
python>>> q="'";s='q="%c";s=%c%s%c;print s%%(q,q,s,q)';print s%(q,q,s,q)
blog
Back to top
View user's profile Send private message
kermitthefrog917
Tux's lil' helper
Tux's lil' helper


Joined: 08 May 2005
Posts: 106

PostPosted: Tue Oct 24, 2006 10:28 pm    Post subject: Re: php exec command Reply with quote

Also, are the variables taken from user input? If so then please make sure they are properly sanitized, otherwise an attacker may some serious harm to your server.

Take a look at http://www.php.net/manual/en/function.escapeshellcmd.php[/quote]

The user uploads a picture, then I rename the picture accordingly and create the thumbnail.

does this fall under the category of user input?
Back to top
View user's profile Send private message
Aurisor
Guru
Guru


Joined: 20 Sep 2003
Posts: 361
Location: Boston MA

PostPosted: Wed Oct 25, 2006 6:43 am    Post subject: Reply with quote

That's probably fine. Just make sure you're using good upload practices, such as hiding any error messages that may come from the command-line output, and checking uploads with is_uploaded_file and so forth. Read more at:

http://us3.php.net/manual/en/features.file-upload.php
Back to top
View user's profile Send private message
Errtu
Apprentice
Apprentice


Joined: 12 Nov 2002
Posts: 155
Location: Brazil

PostPosted: Wed Oct 25, 2006 7:47 am    Post subject: Reply with quote

ishan wrote:
Errtu wrote:
I've also experienced that things work better if you execute exec() with a variable:

Code:
$comnd = "put your command in here";
exec($comnd);


That may keep you more organized but unless there is a SERIOUS bug in your version of PHP that should never affect the output.



Well, i just noticed this in php on apache linux. If i try to pass all kinds of variables to a program, it won't work unless i do it like this. Maybe it has to do with the fact that i need to pass quotes as well as double quotes, i'm not sure. When it finally worked i left it alone :)
Back to top
View user's profile Send private message
kermitthefrog917
Tux's lil' helper
Tux's lil' helper


Joined: 08 May 2005
Posts: 106

PostPosted: Wed Oct 25, 2006 3:54 pm    Post subject: Reply with quote

while I have experienced php programmers watching this, I hope im not out of line to ask a different question...

is ther a way to preserve formatting when storing and recalling data from a mySQL db? The user enters a bunch of information into a textarea, its stored in the database, and then when i call the data, it has some of the formatting still, but HTML strips it. I am looking for a regular expression that will replace the various formatting with the correct ASCII code in HTML.

Thanks
Back to top
View user's profile Send private message
Aurisor
Guru
Guru


Joined: 20 Sep 2003
Posts: 361
Location: Boston MA

PostPosted: Wed Oct 25, 2006 4:04 pm    Post subject: Reply with quote

kermitthefrog917 wrote:
while I have experienced php programmers watching this, I hope im not out of line to ask a different question...

is ther a way to preserve formatting when storing and recalling data from a mySQL db? The user enters a bunch of information into a textarea, its stored in the database, and then when i call the data, it has some of the formatting still, but HTML strips it. I am looking for a regular expression that will replace the various formatting with the correct ASCII code in HTML.

Thanks


Nah, go ahead, I'm bored at work :)

Try htmlspecialchars() and htmlentities() ....those will translate < to &lt; and so forth.

Let me know if I misunderstood your question.
Back to top
View user's profile Send private message
kermitthefrog917
Tux's lil' helper
Tux's lil' helper


Joined: 08 May 2005
Posts: 106

PostPosted: Wed Oct 25, 2006 5:18 pm    Post subject: Reply with quote

Not quite what I needed. The biggest thing I need is the line spacing. Some way to translate a newline character to a <br>.
Back to top
View user's profile Send private message
Corona688
Veteran
Veteran


Joined: 10 Jan 2004
Posts: 1204

PostPosted: Wed Oct 25, 2006 5:24 pm    Post subject: Reply with quote

How about nl2br?
_________________
Petition for Better 64-bit ATI Drivers - Sign Here
http://www.petitiononline.com/atipet/petition.html
Back to top
View user's profile Send private message
zoni
n00b
n00b


Joined: 04 Sep 2006
Posts: 60
Location: The Netherlands

PostPosted: Fri Oct 27, 2006 3:10 pm    Post subject: Reply with quote

Yep, nl2br will convert the newline characters to the correct html tags (<br />). Also, since you're working with user input that's displayed back on a page, make sure you strip out potentially harmfull tags such as <script bla bla bla> to prevent against cross-site-scripting (XSS) and such.

(You didn't state if you stripped tags at all, converting only linebreaks, so just making sure.)
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Portage & Programming All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum