Page 1 of 1

including php in image tag

Posted: Fri Aug 07, 2009 1:02 pm
by orion1977
What I am trying to do is to have an <img> tag where the sourse is a URL with parameters on the end. I have a PHP file which takes in the parameters, munges things, and should return a url to an image it creates based on the parameters passed in.

If I type the complete URL into a browser, the image appears (ie: http://myURL?render_text=myparameter).

If I have a separate webpage (index.php), and use <img src="http://myURL?render_text=myparameter" /> I get nothing.

I am at a loss for how to get this to work. I haven't worked with PHP in quite some time, but I didn't think this would be all that difficult.

Any ideas?

Thanks!

Jenn :banghead:

Re: including php in image tag

Posted: Fri Aug 07, 2009 8:40 pm
by aceconcepts
Can you not assemble the image source before outputting it to the browser?

Re: including php in image tag

Posted: Fri Aug 07, 2009 9:33 pm
by omniuni
Yeah, have the script use a header of time "image/type" where "type" is the type of image, and just display it. That works, but what you have does not. 'src' in HTML tells the browser where to look for the SOURCE of an image, not a URL itself. In other words, just because your script returns the URL of an image, it won't just display it. If you want, try this.

Code: Select all

 
<img src="<?php echo(stripslashes(file_get_contents('http://myURL?render_text=myparameter'))); ?>" alt="image"/>