Hi,
I have a problem with retrieving uploaded images from a database. It appears to upload fine, but when i try to display the image i get loads of binary jargon?
I have tried looking everywhere for a solution, but unable to, any help would be greatly appreciated.
The code for uploading is
include ("database.php");
if(isset($_POST['Submit'])) {
if(isset($_FILES['image'])) {
/* Upload file from anywhere and put in a set temp dir */
$image = file_get_contents($_FILES['image']['tmp_name']);
$image = mysql_real_escape_string($image);
$handle = fopen($image, 'rb'); // read binary
$contents = fread ($handle, filesize ($image));
//$contents = addslashes($contents);
fclose ($handle);
$description = $_POST['description'];
/* Save uploaded file into database */
$query = "INSERT INTO blob_eg.upload VALUES ('', '$image', '$description') ";
$result = mysql_query($query) or die("Couldn't add file to database");
// Check
// echo "<br /> '$query' <br />";
echo "<br /> '$result' <br />";
echo "File uploaded <br /><br />" ;
echo "<a href=\"!upload.html\"> upload more </a><br /><br />" ;
echo "<a href=\"!retrieve.php\"> view image </a><br /><br />" ;
//echo "<input type=\"button\" name=\"retrieve\" value=\"Retrieve image\" ><br />" ;
} // isset upfile
} // isset submit
and the code for displaying is
include ("database.php");
if(isset($_GET['id'])) {
$id = $_GET['id']; }
$query = "SELECT image FROM blob_eg.upload WHERE id='7' ";
$result = mysql_query($query) or die(mysql_error());
if (mysql_num_rows($result) == 0) die("There is no image.");
echo "<br /> '$query' <br />";
echo "<br /> '$result' <br/ > \n";
$row = mysql_fetch_array($result);
$content = $row['image'];
// $content = mysql_real_escape_string($row[image]);
// header("Content-type: image/jpg");
// echo $content ;
echo "<img src=\"!retrieve.php?id='id'\" width=\"250\" height=\"180\" >";
/* while ($row = mysql_fetch_array($result)) {
extract($row);
echo "<img src=!retrieve.php?id='id' width=200 height=150 border=0>";
echo $image; } */