View previous topic :: View next topic |
Author |
Message |
kermitthefrog917 Tux's lil' helper
Joined: 08 May 2005 Posts: 106
|
Posted: Tue Oct 24, 2006 6:07 am Post subject: php exec command |
|
|
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 |
|
|
zoni n00b
Joined: 04 Sep 2006 Posts: 60 Location: The Netherlands
|
Posted: Tue Oct 24, 2006 9:33 am Post subject: |
|
|
For a start, check you php and apache logs, see if anything unusual shows up there. |
|
Back to top |
|
|
gen2fox Guru
Joined: 25 May 2004 Posts: 544
|
Posted: Tue Oct 24, 2006 9:52 am Post subject: |
|
|
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 |
|
|
skunk l33t
Joined: 28 May 2003 Posts: 646 Location: granada, spain
|
Posted: Tue Oct 24, 2006 12:12 pm Post subject: Re: php exec command |
|
|
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 |
|
|
Errtu Apprentice
Joined: 12 Nov 2002 Posts: 155 Location: Brazil
|
Posted: Tue Oct 24, 2006 12:23 pm Post subject: |
|
|
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 |
|
|
Aurisor Guru
Joined: 20 Sep 2003 Posts: 361 Location: Boston MA
|
Posted: Tue Oct 24, 2006 3:10 pm Post subject: Re: php exec command |
|
|
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 |
|
|
Aurisor Guru
Joined: 20 Sep 2003 Posts: 361 Location: Boston MA
|
Posted: Tue Oct 24, 2006 3:10 pm Post subject: |
|
|
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 |
|
|
kermitthefrog917 Tux's lil' helper
Joined: 08 May 2005 Posts: 106
|
Posted: Tue Oct 24, 2006 3:14 pm Post subject: |
|
|
The command convert wasn't in the default path, I needed to specify the full path and it worked perfectly. |
|
Back to top |
|
|
gen2fox Guru
Joined: 25 May 2004 Posts: 544
|
Posted: Tue Oct 24, 2006 3:59 pm Post subject: Re: php exec command |
|
|
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 |
|
|
kermitthefrog917 Tux's lil' helper
Joined: 08 May 2005 Posts: 106
|
Posted: Tue Oct 24, 2006 10:28 pm Post subject: Re: php exec command |
|
|
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 |
|
|
Aurisor Guru
Joined: 20 Sep 2003 Posts: 361 Location: Boston MA
|
Posted: Wed Oct 25, 2006 6:43 am Post subject: |
|
|
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 |
|
|
Errtu Apprentice
Joined: 12 Nov 2002 Posts: 155 Location: Brazil
|
Posted: Wed Oct 25, 2006 7:47 am Post subject: |
|
|
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 |
|
|
kermitthefrog917 Tux's lil' helper
Joined: 08 May 2005 Posts: 106
|
Posted: Wed Oct 25, 2006 3:54 pm Post subject: |
|
|
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 |
|
|
Aurisor Guru
Joined: 20 Sep 2003 Posts: 361 Location: Boston MA
|
Posted: Wed Oct 25, 2006 4:04 pm Post subject: |
|
|
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 < and so forth.
Let me know if I misunderstood your question. |
|
Back to top |
|
|
kermitthefrog917 Tux's lil' helper
Joined: 08 May 2005 Posts: 106
|
Posted: Wed Oct 25, 2006 5:18 pm Post subject: |
|
|
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 |
|
|
Corona688 Veteran
Joined: 10 Jan 2004 Posts: 1204
|
|
Back to top |
|
|
zoni n00b
Joined: 04 Sep 2006 Posts: 60 Location: The Netherlands
|
Posted: Fri Oct 27, 2006 3:10 pm Post subject: |
|
|
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 |
|
|
|