I cannot display an image that is saved in the BLOB database

Asked

Viewed 350 times

0

I saved an image in the BD in a field type BLOB but when displaying it does not display the image, instead it leaves the screen black with a white square in the middle follows the code:

<?php 

 $query = mysqli_query($link, "select * from imagem");

 while($row = mysqli_fetch_array($query)){

     header('Content-Type: image/jpeg');     
     echo '<img src="renderiza.php?id="' . $row["id"] . '"/>';

 }
?>

filing cabinet php rendering.

<?php 
  $link = mysqli_connect("localhost", "root", "", "teste");
  $uid = $_GET["id"];

  $query = mysqli_query($link, "select * from imagem WHERE id = '$uid'");
  $image = mysqli_fetch_array($query);
  $foto = $image['foto'];
  header('Content-Type: image/jpeg');
  echo $image['foto'];

?>
  • You are trying to render the image directly, it will not work. You need to have another file that renders this image in Html.

  • Now I saw that it was edited and better to see. Have you ever tried to render without being in the loop? Directly in html?

  • There are extra quotes in your type code echo '<img src="renderiza.php?id=' . $row["id"] . '"/>';

  • Take a look at this link Function blob2image($mime, $blob){ ob_start(); header("Content-type:$mime"); echo $blob; Return ob_get_contents(); } $mime = 'image/png'; foreach($result as $Row){ echo $Row['name']; echo '<img src="data:'. $mime. ';Base64,'. base64_encode(blob2image($mime, $Row['img'])). '"/>'; }

  • I already answered a similar question in another post. POST All right it was for APP Desktop, but it does not fail to apply to any type of application (Mainly WEB)

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.