问题
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.
回答1:
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.
回答2:
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);
?>
来源:https://stackoverflow.com/questions/10958350/display-image-in-php-page-from-sql-database