MDanz Posted January 9, 2011 Share Posted January 9, 2011 $thephoto = $row['thePHOTO']; in mysql thephoto is BLOB file type and stores an image i want to display the image as an avatar, in a while loop. while($row = mysql_fetch_assoc($query4)) { $id = $row['ID']; $thename = $row['theNAME']; $thephoto = $row['thePHOTO']; } how do i make blob readable and then display as an image? Quote Link to comment https://forums.phpfreaks.com/topic/223824-display-image-from-blob-in-mysql/ Share on other sites More sharing options...
PFMaBiSmAd Posted January 9, 2011 Share Posted January 9, 2011 Each image on a web page requires an <img src="URL_that_results_in_an_image_being_output" alt=""> tag - http://w3schools.com/html/html_images.asp The URL_that_results_in_an_image_being_output that you put into the src="..." attribute would be a URL to your .php file that outputs the correct Content-type: header followed by the binary image data of the correct image. Since you would want to use the same .php file to output any of your images, you would need to use a GET parameter on the end of the URL that specifies which image to output, something like - <img src="image.php?id=some_image_id" alt=""> On your web page you would produce an <img> tag like above for each image. In the image.php code you would access $_GET['id'] to find out which image data to retrieve from the database. You then ouput the correct Content-type: header that matches your image type and then output the binary image data. Quote Link to comment https://forums.phpfreaks.com/topic/223824-display-image-from-blob-in-mysql/#findComment-1156886 Share on other sites More sharing options...
MDanz Posted January 9, 2011 Author Share Posted January 9, 2011 i knew about the img tag.. i did this.. while($row = mysql_fetch_assoc($query4)) { $id = $row['ID']; $thename = $row['theNAME']; $thephoto = $row['thePHOTO']; echo "<img src='$thephoto' alt='photo' />"; } where do i put header('Content-type:image/jpeg'); Quote Link to comment https://forums.phpfreaks.com/topic/223824-display-image-from-blob-in-mysql/#findComment-1156891 Share on other sites More sharing options...
PFMaBiSmAd Posted January 9, 2011 Share Posted January 9, 2011 Unless $thephoto contains a URL where the image is actually stored at, that code would not work and doesn't do what someone took the time to explain and post a link to information about. Quote Link to comment https://forums.phpfreaks.com/topic/223824-display-image-from-blob-in-mysql/#findComment-1157042 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.