monkeytooth Posted August 4, 2010 Share Posted August 4, 2010 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? Quote Link to comment Share on other sites More sharing options...
Skewled Posted August 4, 2010 Share Posted August 4, 2010 You need to use the header() function in the first line of the PHP file. Then code in your php file to do what you need with the actual php to display the image. http://us3.php.net/image may be a bit of help for you also. Quote Link to comment Share on other sites More sharing options...
phil88 Posted August 4, 2010 Share Posted August 4, 2010 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. Quote Link to comment Share on other sites More sharing options...
monkeytooth Posted August 5, 2010 Author Share Posted August 5, 2010 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. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.