including php in image tag

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
orion1977
Forum Newbie
Posts: 1
Joined: Fri Aug 07, 2009 12:52 pm

including php in image tag

Post 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:
User avatar
aceconcepts
DevNet Resident
Posts: 1424
Joined: Mon Feb 06, 2006 11:26 am
Location: London

Re: including php in image tag

Post by aceconcepts »

Can you not assemble the image source before outputting it to the browser?
User avatar
omniuni
Forum Regular
Posts: 738
Joined: Tue Jul 15, 2008 10:50 pm
Location: Carolina, USA

Re: including php in image tag

Post 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"/>
Post Reply