Jump to content

Displaying blob images


songu

Recommended Posts

Hello

 

I am trying to create an image gallery that allows other users to upload images into. I want all the images to be displayed on the one page. I've figured out how to do this by using a table with a blob field. I've decided not to put the images in the directory as this method seems like it would be too complicated for my application.

 

My problem: All the data is displaying properly, apart from the images. The images are being displayed as binary text. I have a suspicion that the header line is in the wrong place and that the "<img src='$imgdata'>" line is wrong, but I'm very new to PHP so I'm not sure. Any help would be very much appreciated.

 

Thanks

 

 

<html>
<table width="100%">
<tr>
	<td>ID</td>
	<td>Item Image</td>
</tr>
<?php
$query = "SELECT * FROM pix";
$result = mysql_query($query, $connection) or die(mysql_error());
header("Content-type: image/jpeg");
while ($row = mysql_fetch_array($result)) {
$pid = $row['pid'];
$imgdata = $row['imgdata'];
?>

<tr>
	<td><?php echo $pid; ?></td>
	<td><?php echo "<img src='$imgdata'>"; ?></td>
</tr>

<?php
}
?>
</table>

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.