Display image in php page from sql database [closed]

穿精又带淫゛_ 提交于 2019-12-13 11:29:25

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!