Jump to content

img src as php file


monkeytooth

Recommended Posts

Ive been looking around and I can't seem to find a straight answer so its left me unable to really figure it out on my own. I have seen it done on several sites over the years I have been coding. But now Ive come to a cross road where I want to do something thats similar.

 

I have a directory of images, well a couple actually but thats neither here nor there. What I want to do is use an HTML formated image tag with a php file as the source name. Example..

<img src="images.php" border="0" />

 

I want to do this so I can offer an image I can update regularly or at random depending on what the cause is but allow people to hotlink that specific image src tag. Is there anyone here thats done it before that can point me in the right direction?

Link to comment
Share on other sites

All the images.php file will do is create an image using GD/whatever, or read in the image from a file somewhere eg, using file_get_contents('something.png'); and then echo it with the appropriate header.

 

For example;

$imageContents = file_get_contents('animage.png');
header('Content-Type: image/png');
echo $imageContents;

 

The header just tells the web browser to display what the script is sending it as a png image rather than trying to treat it as a text.

Link to comment
Share on other sites

i figured it was something with the headers, as Ive applied that to various types of media up like css or javascript. Just thought it would be a bit more elaborate than calling out the image after the header. And really couldnt find an answer that was well, straight forward about it.. thanks for your help, ill have to give those a shot.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.