Hi all,
I have some code I can't get to work. It's taken from the article "Storing Binary Data In a DB":
http://www.phpbuilder.com/columns/florian19991014.php3
My code is slightly modified, but it's the same principle.
Problem: I get a broken image when I use getdata.php... Can any one help me out?
Here's my code:
datamodel
CREATE TABLE binary_data (
id INT(4) NOT NULL AUTO_INCREMENT PRIMARY KEY,
description CHAR(50),
bin_data LONGBLOB,
filename CHAR(50),
filesize CHAR(50),
filetype CHAR(50)
);
getdata.php
<?php
require ("../config.inc");
if($id) {
$db = @mysql_connect("localhost", "root", "qwsmet") or die("Can't connect to server.");
@mysql_select_db("magazine", $db) or die("Can't select database.");
$query = "select bin_data,filetype from binary_data where id=$id";
$result = @($query) or die("Couldn't get image.");
$data = @mysql_result ($result,0,"image");
$filetype = @mysql_result ($result,0,"filetype");
header("Content-type: $filetype");
echo "$data";
};
?>