Jump to content

Fetching BLOB images from MySQL in PHP


arsis

Recommended Posts

Hey I've been having a bit of trouble with this. My final product is going to be a table with data and a Snapshot that is paginated across however many pages. With my current code I've gotten a data table that displays MySQL data and paginates it correctly, the only thing I am stuck on is the ability to retrieve BLOB type jpegs. 

 

With this code I am able to fetch the image but just as raw text, I suppose its just dumping the image as characters, but it works none the less... I just need to let it know to display it as a jpeg image.


$sql_query = "SELECT `Snapshot` FROM `DoorEvents` ORDER BY `DoorEvents`.`Id` ASC LIMIT 0,1 ";// MySQL query and formatting
$result = @MySQL_query($sql_query, $conn);
while ($row = mysql_fetch_assoc($result)) {
   // echo data
echo "<img src=".$row['Snapshot'].". alt='photo'>";

 

I know this isnt the way to do it... buts its a step in the right direction. Can anyone point me in the right one?

Link to comment
Share on other sites

Images require a URL that when fetched by the browser outputs the proper content type header for the image, followed by the image data - http://w3schools.com/html/html_images.asp

 

The URL you supply in your <img src="..."> tag would be to a .php page that gets the correct image from the database, outputs a header and the image data.

Link to comment
Share on other sites

Images require a URL that when fetched by the browser outputs the proper content type header for the image, followed by the image data - http://w3schools.com/html/html_images.asp

 

The URL you supply in your <img src="..."> tag would be to a .php page that gets the correct image from the database, outputs a header and the image data.

 

Thanks, So like point it to a "getimage.php" or something? I need to output all the images in the Snapshot row, not just a specific one...

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.