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
https://forums.phpfreaks.com/topic/141115-fetching-blob-images-from-mysql-in-php/
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.

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...

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.