Jump to content

display image from blob in mysql


MDanz

Recommended Posts

	$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?

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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'); 

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.