-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.

3
  • 4
    "Please Help me to read". Help us first. Commented Jun 9, 2012 at 4: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. Commented Jun 9, 2012 at 4:54
  • And what code are you using to extract the image from the database and display it? Commented Jun 9, 2012 at 17:22

2 Answers 2

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.

Sign up to request clarification or add additional context in comments.

Comments

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);
?>

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.