CharlesCA Posted June 18, 2009 Share Posted June 18, 2009 How do I display an image if I have the jpeg image as a string? Ideally I just want to use the img src tag so I can have other output on the webpage, without having to write the string of a file or creating a new page for just the image. I have tried the following (and they work): • Write the string to a file and use img src tag • Set the content type to image/jpeg and write the string to a new page with nothing else on it Quote Link to comment https://forums.phpfreaks.com/topic/162835-display-image-if-i-have-it-as-a-string/ Share on other sites More sharing options...
CharlesCA Posted June 18, 2009 Author Share Posted June 18, 2009 I just read this thread about someone with the same problem: http://www.phpfreaks.com/forums/index.php/topic,251428.0.html Is there really no solution that works? ??? Quote Link to comment https://forums.phpfreaks.com/topic/162835-display-image-if-i-have-it-as-a-string/#findComment-859270 Share on other sites More sharing options...
MadTechie Posted June 18, 2009 Share Posted June 18, 2009 you need to open it in a file with the correct header ie <?php $data = file_get_contents("myImage.jpg"); //get the images data (from database or whatever) header('Content-Type: image/jpeg'); //Set header echo $data; ?> Okay when you open that file it will display the image! EDIT: this should be it OWN file.. to display it in a html page just call the php script above as if it was the image heres another example myimage.php <?php $data = file_get_contents($_GET['file']); //get the images data (from database or whatever) header('Content-Type: image/jpeg'); //Set header echo $data; ?> in the HTML i would do this <img src="myimage.php?file=theImage.jpg"> *these are just for an example* Quote Link to comment https://forums.phpfreaks.com/topic/162835-display-image-if-i-have-it-as-a-string/#findComment-859283 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.