Hello everyone,
I am building a web application for my school (I am learning php as i go along) and I am storing some images into a DB table as BLOBs. I am trying to retrieve them now, and I have a script that seems to work but for one problem
when i echo the variable where i store the blob it returns the binary data even when I add the header needed that should return the image, i get a bunch of weird code on the page.
I am aware that storing the images in a file system is more efficient, But I just wanted to see this work.
thanks in advance...
heres the code
I am building a web application for my school (I am learning php as i go along) and I am storing some images into a DB table as BLOBs. I am trying to retrieve them now, and I have a script that seems to work but for one problem
when i echo the variable where i store the blob it returns the binary data even when I add the header needed that should return the image, i get a bunch of weird code on the page.
I am aware that storing the images in a file system is more efficient, But I just wanted to see this work.
thanks in advance...
heres the code
Code:
<?php
mysql_connect(localhost,root,root);
mysql_select_db(upload);
//echo "hello";
// I am just getting the first table row to try it out
$query="SELECT * FROM upload";
/*$query = "SELECT name, type, size, content ".
******** "FROM upload WHERE id = '41'";*/
$result = mysql_query($query) or die('Error, query failed');
$row = mysql_fetch_array($result);
$content=$row['content'];
$name=$row['name'];
//header("Content-length: $size");
//header("Content-Disposition: attachment; filename=$name");
header("Content-type: image/jpeg");
print $content;
exit;
?>