-6

I'm trying to display image in php page from a SQL database. When i try i see: ÿØÿàJFIFHHÿáWExifMM* instead of the image that I expected. Please Help me to read or display this as an image.

PresleyDias
  • 3,657
  • 6
  • 36
  • 62
Sukumol
  • 1
  • 1
  • 2
  • 4
    "Please Help me to read". Help us first. – Érik Desjardins Jun 09 '12 at 04:38
  • 1
    It would be better to just store the file path in the database and then reference the image file in your HTML instead of storing the actual image data in the database. Regardless of that, there are many tutorials on [Google](https://www.google.com/search?q=php+mysql+store+image). – sachleen Jun 09 '12 at 04:54
  • And what code are you using to extract the image from the database and display it? – Kevin Jun 09 '12 at 17:22

2 Answers2

2

Most likely you're not outputting a content-type header, so the server and/or browser are assuming you're ouputting plain text, and displaying it as such:

<?php

// database stuff here

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

should fix it up.

Marc B
  • 356,200
  • 43
  • 426
  • 500
0

I belive a good solution would be load the image from a string (you table column for instance), and as you don't know the type, you could force GD to print a specific type (in this case JPEG), as follows:

<?
 ...
 $data = $row["line"];

 $new_im = imagecreatefromstring($data)

 Header("Content-Type: image/jpeg");
 Header("Content-Description: PHP Generated Image");

 imagejpeg($new_im);
?>
Francisco Spaeth
  • 23,493
  • 7
  • 67
  • 106