2

我在让它工作时遇到了一些困难。

这是我正在使用的代码:

require_once('db_connection.php');
$Query = mssql_query("SELECT Photo FROM Persons WHERE IDPerson = '3'");
$Person = mssql_fetch_array($Query);
$Photo = $Person["Photo"];
header('Content-type: image/jpeg');
echo $Photo;

这是我得到的结果:

在此处输入图像描述

(图像底部出现了一些东西,但这只是图像的一部分)

这是图像值在我的数据库中的样子:

0x424D3684030000000000360000002800000040010000F000000001001800000000000084030000000000000000000000000000000000FDFEF5FCFDF4FFFFFAE3F2

有任何想法吗?

4

1 回答 1

2

您应该必须使用 base64 编码来显示数据库中的图像

喜欢

<img src="data:image/jpeg;base64,/9j/4AAQSkZJRgABAQEAWgBaAAD/4gxYSUNDX1BST0ZJTEUAAQEAAAxITGlubwIQAAB..." />

使用,base64编码

<?php
$Query = mssql_query("SELECT Photo FROM Persons WHERE IDPerson = '3'");
$Person = mssql_fetch_array($Query);
$Photo = $Person["Photo"];

$mime = null;
// place $type init. here
if ($type=="pjpeg") // <<< where do you get $type btw?
    $mime = "image/jpeg";

$b64Src = "data:".$mime.";base64," . base64_encode($Photo);
echo '<img src="'.$b64Src.'" alt="" />';
?>

例如

header("Content-type: image/png");

echo base64_decode('iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAABGdBTUEAAK/INwWK6QAAABl0RVh0U29mdHdhcmUAQWRvYmUgSW1hZ2VSZWFkeXHJZTwAAAHhSURBVDjLjZPLSxtRFIfVZRdWi0oFBf+BrhRx5dKVYKG4tLhRqlgXPmIVJQiC60JCCZYqFHQh7rrQlUK7aVUUfCBRG5RkJpNkkswrM5NEf73n6gxpHujAB/fOvefjnHM5VQCqCPa1MNoZnU/Qxqhx4woE7ZZlpXO53F0+n0c52Dl8Pt/nQkmhoJOCdUWBsvQJ2u4ODMOAwvapVAqSJHGJKIrw+/2uxAmuJgFdMDUVincSxvEBTNOEpmlIp9OIxWJckMlkoOs6AoHAg6RYYNs2kp4RqOvfuIACVFVFPB4vKYn3pFjAykDSOwVta52vqW6nlEQiwTMRBKGygIh9GEDCMwZH6EgoE+qHLMuVBdbfKwjv3yE6Ogjz/PQ/CZVDPSFRRYE4/RHy1y8wry8RGWGSqyC/nM1meX9IQpQV2JKIUH8vrEgYmeAFwuPDCHa9QehtD26HBhCZnYC8ucGzKSsIL8wgsjiH1PYPxL+vQvm5B/3sBMLyIm7GhhCe90BaWykV/Gp+VR9oqPVe9vfBTsruM1HtBKVPmFIUNusBrV3B4ev6bsbyXlPdkbr/u+StHUkxruBPY+0KY8f38oWX/byvNAdluHNLeOxDB+uyQQfPCWZ3NT69BYJWkjxjnB1o9Fv/ASQ5s+ABz8i2AAAAAElFTkSuQmCC');

如果您的字符串是这样的,它将打印 pdf 徽标

于 2013-04-25T11:20:24.557 回答