Problem Viewing Image in MySQL DB
Posted: Sun May 11, 2008 9:50 pm
I am trying to simply take an image from a table and place it into a php file at a place of my choosing (whether it be next to text or in a table). I've gotten images to save to the table using a script I found and edited; however, when I enact the script to view the images it just views the images...nothing else. I need to be able to see more than just the image. In anycase....here's my current code:
It displays an image with an ID given by the URL via GET. Currently, it works, it just doesn't allow me to display anything other than the text. Sometimes it gives me an error, other times it just doesn't even display text I echo within the document. When I add html tags such as this:
It gives me the following errors:
Warning: Cannot modify header information - headers already sent by (output started at C:\xampp\htdocs\imagetest\showimage.php:4) in C:\xampp\htdocs\imagetest\showimage.php on line 18
Warning: Cannot modify header information - headers already sent by (output started at C:\xampp\htdocs\imagetest\showimage.php:4) in C:\xampp\htdocs\imagetest\showimage.php on line 19
...And then spits out really nasty looking random characters that I suppose represent the binary making up the image in the table.
How could I fix this problem?
Code: Select all
<?php
$con = mysql_connect("localhost","root","");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("test_db", $con);
$result = mysql_query("SELECT * FROM ae_gallery WHERE id='$_GET[show]' LIMIT 1");
$row = mysql_fetch_assoc( $result );
$imageData = $row['data'];
$imageExt = $row['ext'];
header('Content-Length: '.strlen($imageData));
header("Content-type: image/{$imageExt}");
echo $imageData;
mysql_close($con);
?>Code: Select all
<html>
<body>
<?php
$con = mysql_connect("localhost","root","");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("test_db", $con);
$result = mysql_query("SELECT * FROM ae_gallery WHERE id='$_GET[show]' LIMIT 1");
$row = mysql_fetch_assoc( $result );
$imageData = $row['data'];
$imageExt = $row['ext'];
header('Content-Length: '.strlen($imageData));
header("Content-type: image/{$imageExt}");
echo $imageData;
mysql_close($con);
?>
THIS IS TEST TEXT
</body>
</html>Warning: Cannot modify header information - headers already sent by (output started at C:\xampp\htdocs\imagetest\showimage.php:4) in C:\xampp\htdocs\imagetest\showimage.php on line 18
Warning: Cannot modify header information - headers already sent by (output started at C:\xampp\htdocs\imagetest\showimage.php:4) in C:\xampp\htdocs\imagetest\showimage.php on line 19
...And then spits out really nasty looking random characters that I suppose represent the binary making up the image in the table.
How could I fix this problem?