这是我的实际代码,我开始使用php,我想知道如何在我的网站上显示blob图像。 但直到现在我还无法找到如何做到这一点。这是我的PHP代码......
$query=mysqli_query($link, "SELECT image, titulo, tecnica, medidas FROM upload ");
$numrows = mysqli_num_rows($query);
$posts = array();
if ($numrows != 0)
{
while ($row = mysqli_fetch_assoc($query))
{
$post = new stdClass();
$post->image = '<img src="data:image/jpeg;base64,'.base64_encode($row['image']).'"/>';
$post->titulo = $row['titulo'];
$post->tecnica = $row['tecnica'];
$post->medidas = $row['medidas'];
array_push($posts, $post);
}
}
$jsonData = json_encode($posts);
header("Content-Type: image/jpeg");
echo $jsonData;
答案 0 :(得分:0)
试试这个:
<?php
//Connect to the database
$databasehost = "YOUR DATABASE HOST";
$databasename = "YOUR DATABASE NAME";
$databaseusername ="YOUR DATABASE USERNAME";
$databasepassword = "YOUR DATABASE PASSWORD";
$con = mysqli_connect($databasehost, $databaseusername, $databasepassword, $databasename) or die(mysqli_error($con));
mysqli_set_charset ($con, "utf8");
$sql = "SELECT image, titulo, tecnica, medidas FROM upload;";
$res = mysqli_query($con, $sql);
$result = array();
while($row = mysqli_fetch_array($res)) {
array_push($result,
array(
'image'=>base64_encode($row[0]),
'titulo'=>$row[1],
'tecnica'=>$row[2],
'medidas'=>$row[3]
));
}
echo json_encode(array($result));
mysqli_close($con);
这将打印您的数据:
{[{“image”:“基本编码的图像”,“titulo”:“ SOME DATA “,”tecnica“:”某些数据“,”medidas“:”某些数据“},
{“image”:“基本编码的图像”,“titulo”:“ SOME DATA “,”tecnica“:”某些数据“,”medidas“:”某些数据“},
{“image”:“基本编码的图像”,“titulo”:“ SOME DATA “,”tecnica“:”某些数据“,”medidas“:”某些数据“}}}
希望它有所帮助!祝好运!快乐的编码!