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.Érik Desjardins– Érik Desjardins2012-06-09 04:38:17 +00:00Commented Jun 9, 2012 at 4:38
-
1It 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.sachleen– sachleen2012-06-09 04:54:17 +00:00Commented Jun 9, 2012 at 4:54
-
And what code are you using to extract the image from the database and display it?Kevin– Kevin2012-06-09 17:22:24 +00:00Commented Jun 9, 2012 at 17:22
Add a comment
|
2 Answers
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);
?>