Mega Code Archive
How to show images stored in a database
There have been a number of questions lately about storing images in a db table and then how to show them correctly. The problem is that the header for images needs to be set correctly for the binary data to be show correctly.
Here are the two working pages (tested my machine (xp, apache2, php4.3.9 mysql 4.01.x)
In the areas for the db query you will see the notation
$result = connect(sql);
connect is a custom function to handle all db interatction that is separate from the pages and included in the conn.php file. There is another example with that function in my previously posted code samples.
";
echo "
\n";
};
?>
Database table:
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)
);