converting BLOB to jpeg MySQL/PHP

Soldato
Joined
10 Apr 2006
Posts
7,890
Location
North West
Second post in a few days, keep getting stuck on things :(

Quick run over of tables im using for this:

Package, Picture, package_picture.

Package contains all the data and Package_ID.
Picture contains the BLOB and Picture_ID.
Package_Picture contains Picture_ID & Package_ID.

Package_ID links the 3 tables together.

I have package.php which queries the db and pulls out the relevant data, but I need it to pull out the image in "Picture".

In package.php I have:
PHP:
$imageID = $_GET['id'];
<img src="image_test.php?id=<?php print $imageID; ?>" >
Gets the ID of the package currently being viewed and posts the image_test.php for the image.

In image_test.php I have:
PHP:
<?php
header("Content-Type: image/jpg");
require("functions.php"); //Gets all the functions
dbConnect(); //Connects to the database
$imageid = $_GET['id'];
if ($imageid) {
		$sql = "SELECT image, description, package_ID FROM picture, package, package_picture WHERE package_ID = {$_GET['id']}";
    $result = mysql_query($sql);
    $data = mysql_result($result, 0, "bin_data");
    $type = mysql_result($result, 0, "filetype");
    $bytes = $row['image'];
    print $bytes;
}
?>

Its probably something daft that I have missed out, but its really irritating me and I cant find what it is!

Thanks anyone :D
 
If i use that code it outputs

<img src="image_test.php?id=3" >

In the source but nothing on the page but its obviously me doing something wrong.

The $bytes was taken from an example I found somewhere.

The picture.image holds the BLOB data that has a picture.picture_ID alongside it, the picture_ID is linked to the specific package by package_package_ID.

i thought I can just substitute the actual img src path with a php file an it would output the image or do I have wrong of the stick ?
 
thanks a lot, ill try it now :)

looked through loads of examples on the net but they all were linked with an upload feature and I couldnt get this to work as its using multiple tables.

The ID gets pulled ok it just wouldn't display the image, ill try it after i get a shower :)
 
Thats what I dont know, I didnt create the database, someone else did and they have people inserting data into it, so I've never worked with BLOBs before thats why its awkward lol.
 
Well the database was designed by someone doing their masters in software engineering, Im just doing the php side of things and learning as i go along so his decision for all the db things :D will tell him what you said though :p
 
Back
Top Bottom