Page 1 of 1

Trying to display a blob ...

Posted: Tue Oct 20, 2009 7:50 am
by stirnpanzer
Am trying to display some php fields in a html table....

all ok except the blob file 'person_photo' which displays as garbage...

is it syntax or me ??

Code: Select all

 
[color=#BF0000]<?php[/color]
 
$query = "select * FROM people WHERE person_country = 81" ; 
 
$data = mysql_query($query) ; 
Print $query;
 
Print "<table width='100%' height='1000' border cellpadding=1>"; 
while($info = mysql_fetch_array( $data )) 
{ 
Print "<tr>";
Print "<td height='59'>&nbsp;</td>";
Print "<td >Lastname : " .$info['person_lastname'] . "</td>";
Print "<td width='20%>&nbsp;</td>";
Print "<td width='18%'>Firstname : ".$info['person_firstname'] . "</td>";
Print "<td width='18%'>&nbsp;</td>";
Print "<td width='22%' rowspan='5'>Photo : " . header('Content-Type: image/jpeg') .$info['person_photo'] . "</td>";
Print "<td width='5% rowspan='7'>&nbsp;</td>";
Print "</tr>";
 
Print "</table>";
} 
 
[color=#BF0000]?>[/color]

Re: Trying to display a blob ...

Posted: Tue Oct 20, 2009 8:11 am
by Baronen
You can't change the header after its sent to the browser.

Code: Select all

Print "<td width='22%' rowspan='5'>Photo : " . header('Content-Type: image/jpeg') .$info['person_photo'] . "</td>";
You are trying to set the header as a image/jpeg.

You have to create a new PHP file that has the header image/jpeg.

display_image.php

Code: Select all

 
$person_country = $_GET['person'];
//Make an sql to get the image
header('Content-Type: image/jpeg');
 
echo $info['person_photo'];
 
 
And then

Code: Select all

 
Print "<td width='22%' rowspan='5'>Photo : <img src='display_image.php?person=81' /></td>";
 
Maybe not the best solutions. But it works

Re: Trying to display a blob ...

Posted: Tue Oct 20, 2009 8:23 am
by AbraCadaver
You can't just display the blob in the inline HTML, you have to do it the way images are done in HTML. Something like this (untested):

image.php

Code: Select all

// change this to whatever you have as primary key
$id = (int)$_GET['id'];
$query = "SELECT * FROM people WHERE person_id = $id";
$data = mysql_query($query);
$info = mysql_fetch_array($data);
 
header('Content-type: image/jpeg');
$info['person_photo'];
line 18 in your code

Code: Select all

<!-- change $info['person_id'] to your primary key
Print "<td width='22%' rowspan='5'>Photo: <img src='image.php?id=" . $info['person_id'] . "' alt='whatever' /></td>";
-Shawn

Re: Trying to display a blob ...

Posted: Tue Oct 20, 2009 11:09 am
by stirnpanzer
image.php :

Code: Select all

<?php
// change this to whatever you have as primary key
$id = (int)$_GET['id'];
$query = "SELECT * FROM people WHERE id = $id";
$data = mysql_query($query);
$info = mysql_fetch_array($data);
 
header('Content-type: image/jpeg');
$info['person_photo'];
 
?>
display_person.php

Code: Select all

Print "<td width='22%' rowspan='5'>Photo: <img src='image.php?id=" . $info['person_id'] . "' alt='Picture here' /></td>";
 
It is retuning a broken image link... but with with all the correct info in the source ...

"http://localhost/xampp/mydb/image.php?id=10"

where 10 = person_id, it is showing the correct details for person 10 , eg: name etc...

and there is an image in the blob field "person_photo" for person 10

Any ideas..

Re: Trying to display a blob ...

Posted: Tue Oct 20, 2009 11:51 am
by AbraCadaver
Well damn. I omitted the echo in the image.php:

$info['person_photo'];

should be:

echo $info['person_photo'];