Jump to content

my blobbing problem...please help


papalazarou

Recommended Posts

ok ive been trawling through so many tutorials and just cant seem to get this to work. i want to be able to display a blob jpeg file in a table on a html page.

 

<html>

<head>
<title>The Bassment: Photo Gallery</title>
</head>

<BODY bgcolor="#006699">
<?php
$db_host = 'localhost';
$db_user = '*****';
$db_pwd = '*****';

$database = 'jenkem_flash';
$table = 'ae_gallery';

if (!mysql_connect($db_host, $db_user, $db_pwd))
    die("Can't connect to database");

if (!mysql_select_db($database))
    die("Can't select database");

// sending query
$result = mysql_query("SELECT * FROM {$table} order by id");
if (!$result) {
    die("Query to show fields from table failed");
}

$fields_num = mysql_num_fields($result);

echo "<h1>Photo Gallery</h1>";
echo "<table border='2'><tr>";
// printing table headers
for($i=0; $i<$fields_num; $i++)
{
    $field = mysql_fetch_field($result);
    echo "<td><b>{$field->name}</b></td>";
}
echo "</tr>\n";
// printing table rows
while($row = mysql_fetch_row($result))
{
    echo "<tr>";

    // $row is array... foreach( .. ) puts every element
    // of $row to $cell variable
    foreach($row as $cell)
        echo "<td>$cell</td>";

    echo "</tr>\n";
}
mysql_free_result($result);
?>
</body>
</html>

 

This code outputs a html table with all the field headings and information, however for the actual blob file all that comes out is a bunch of jargonned syntax. any help would be so much appreciated ive been up all night  :-\

Link to comment
Share on other sites

Kalhmera,

 

What you need to understand is that you did not tell the browser that your binary data is an image.

Blob stores binary data. We need to let the browser know it is an image.

 

Now, the problem is there is no html tag to do that. You have to use the standard img tag like the image was not on a database but it was a file.

Make a script that outputs only the image for a given id (e.g. image.php?id=whatever). Do note that you will need to use the header() command to specify that you are outputting an image.

 

Then in your main script, in the part of the table you want to display the image, instead of sending the binary data, use img src="image.php?id=..."

 

That 's the outline, for the actual implementation, well, it's up to you. :)

Link to comment
Share on other sites

thanks for your reply, i do understand the theory behind doing this kind of. im just totally stuck here and dont know where to go next. the example above was the closest i got cos it is at least outputting something.

 

im assuming somewhere im going to have to use something like

 

header ("Content-Type: image/jpeg"); 
echo $row['data']; 

 

but dont know how to apply it, should that be in a seperate php file or i dunno i have no idea im totally new, ive only been learning php the past week and arnt competant enough to code myself. is the form i have created above actually going to work once it is outputting a jpg rather than binary data. heeeeeellpp meeeee  ;D

 

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.