sandy1028 Posted June 7, 2010 Share Posted June 7, 2010 //DB Connection $sql ="select img_val from image where id=152"; $result = mysql_query($sql); while ($row = mysql_fetch_assoc($result)) { $Image=$row['img_val']; # print "Image is $Image"; } header( "Content-type: image/jpeg"); echo "<img src=\"$Image\"; alt=\"Image from DB\" />"; When I view the file in browser, some characters are printed and not the image. Please tell me how to view the exact image in the browser. Quote Link to comment https://forums.phpfreaks.com/topic/204068-view-image-in-browser/ Share on other sites More sharing options...
premiso Posted June 7, 2010 Share Posted June 7, 2010 header( "Content-type: image/jpeg"); echo $Image; It expects the raw data of the image, not an html tag. Try that. (And you do not need the while loop since you are only pulling 1 record) Quote Link to comment https://forums.phpfreaks.com/topic/204068-view-image-in-browser/#findComment-1068842 Share on other sites More sharing options...
sandy1028 Posted June 7, 2010 Author Share Posted June 7, 2010 In the browser I can see some characters and not the image. [attachment deleted by admin] Quote Link to comment https://forums.phpfreaks.com/topic/204068-view-image-in-browser/#findComment-1068846 Share on other sites More sharing options...
PFMaBiSmAd Posted June 7, 2010 Share Posted June 7, 2010 The <img src="..." attribute value MUST BE a URL to an image, NOT binary image data. The URL that you put into the src="..." attribute must cause the correct Content-type: header to be output, followed by the binary image data. Since you are outputting the binary image data using a .php script, you would put a .php file in as the URL. You will also typically put a GET parameter on the end of the URL that indicates which image you want (so that you can use the same .php file to output any available image.) The <img tag that you produce for your web page would look something like - <img src="myimage.php?id=152" alt=""> The myimage.php file (or whatever name you choose) will need to get the id (using $_GET['id']), validate it, and put that into the query in order to retrieve the correct binary image data. Quote Link to comment https://forums.phpfreaks.com/topic/204068-view-image-in-browser/#findComment-1068858 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.