Forum Moderators: coopster

Message Too Old, No Replies

Replacing variable from form...

         

Fuzzyhaggis

1:21 pm on Aug 15, 2005 (gmt 0)

10+ Year Member



I'm trying to put together a web magazine (partly in order to teach myself php!) and I've run into a wall.

I want users to be able to upload an image (easy peasy) and then have the script spit out the <img...> tag so the user can just past it into the form and it will appear by magic! The problem is, I have my root directory defined in a variable on every page (i.e. $root_path = "./../../../"; for example) and I want the form to pick this up. At the moent, if I paste something like....

<img src=\"". $root_path . "features/news/images/dartvador.jpg\">

into the form, it just prints the $root_path variable as "$root_path". How can I get it to replce it? It works fine if I just define it as a seperate variable (i.e. not from the form).

coopster

3:03 pm on Aug 15, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Welcome to WebmasterWorld, Fuzzyhaggis.

You need to echo [php.net] or print [php.net] that information to the browser.

print '<img src="' . $root_path . 'features/news/images/dartvador.jpg"' />

Fuzzyhaggis

3:22 pm on Aug 15, 2005 (gmt 0)

10+ Year Member



Yep - that's fine if I just want to output it, but what happens if it's coming from a form on a previous page?

Basically, what I'm trying to do is have an editor upload an image via a form and then get back the piece of html.php code which they just need to paste into a form and submit as part of the rest of their story. The difficult bit is that I want all image links to start at the root directory.

coopster

3:37 pm on Aug 15, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Why not use the $_SERVER['DOCUMENT_ROOT'] superglobal [php.net] variable?

Fuzzyhaggis

8:02 am on Aug 16, 2005 (gmt 0)

10+ Year Member



Not heard of that one - how does it work?

Come to think of it - part of the problem might be that I don't really want to go right back to the root directory but a subdirectory off that.

What I really want to do is to get the server to process text sent from a form as if it were a piece of php.

coopster

11:29 am on Aug 16, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Have a look at message number 17 regarding how to Control your included files in Good PHP solutions to small problems [webmasterworld.com].