我几天前发帖 Pass MySQL medium blob into IOS NSData\UIImage 但是还没有设法找到解决方案。我的具体问题是,当我从数据库,blob或文本中检索图像时,它返回NULL,其中没有变量的行只返回空白
while ($row = mysql_fetch_array($result)) {
$add = array();
$add["Id"] = $row["Id"];
$add["Mail"] = $row["Mail"];
$add["Category"] = $row["Category"];
$add["Phone"] = $row["Phone"];
$add["Msgs"] = $row["Msgs"];
//image from blob
$add["Picture"] = $row["Picture"];
// push single add into final response array
array_push($response["adds"], $add);
}
还有其他方法可以解决blob \ text中的图像吗?!我试过https://stackoverflow.com/a/6273415/1333294,但对我没什么用。
答案 0 :(得分:1)
最后!!
$img = $row["Picture"];
$b64img = base64_encode ($img);
$b64img = mysql_real_escape_string($b64img);
$add["Picture"] = $b64img;
这很简单!和xcode得到它作为base64字符串和坚果NULL。谢谢你的建议...
答案 1 :(得分:0)
添加以下代码
header("Content-type: image/jpeg");
echo $row['picture'];
// Display image with img html tag
echo '<img src="data:image/jpeg;base64,' . base64_encode( $row['picture'] ) . '" />';
echo 'Hello world.';
请查找示例代码
$response["adds"] = array();
$add = array();
$add["Id"] = 1;
$add["Mail"] = "test@mm.com";
$add["Category"] = "category";
$add["Phone"] = "1234567";
$add["Msgs"] = "ths s txt msg";
//image from blob
$add["Picture"] = "pciture";
// push single add into final response array
array_push($response["adds"], $add);
print_r($response["adds"]);
header("Content-type: image/jpeg");
print $response["adds"][0]['Picture'];