0

This is my HTML code for displaying image stored as blob object which is stored in a database.

<tr><td>photo</td><td><img src="image.php?id=<?php echo $employee['id']; ?>" /></td></tr>

This is the image.php file:

<?php

include db.php;

$employee_id = (isset($_GET['id']) && is_numeric($_GET['id'])) ? intval($_GET['id']) : 0;

try
{ 
  $sql = "SELECT photo
          FROM employee where id = $employee_id limit 1";
  $s = $pdo->prepare($sql);
  $s->execute();
} 
catch (PDOException $e)
{ 
  $error = 'Employee not found' . $e->getMessage();
  include 'error.html.php';
  exit();
} 

$employee = $s->fetch();

$image = $employee['photo'];

header('Content-Type: image/jpeg');
echo $image;

?>

When I look at the HTML code in Firebug, I can see

<img src="image.php?id=9">

But no image is displayed in the table row. Do you know how to find out what is wrong?

When I open the page ...image.php?id=9 in Firefox It shows a message

The image ...image.php?id=9 cannot be displayed because it contains errors.

It is strange that every image I have contains an error. I inserted only images with size smaller than the blob object.

xralf
  • 3,312
  • 45
  • 129
  • 200

1 Answers1

0

do you get an error?

try to use "exit;" after the echo and remove the closing php tag. it's optional and you don't really need it (http://php.net/manual/en/language.basic-syntax.instruction-separation.php).

header('Content-Type: image/jpeg');
echo $image;
exit;
stefan
  • 4,958
  • 4
  • 20
  • 37