-1

I want to display an BLOB image on PHP. I can insert normally using the website PHP, but I can't display. Can someone help me? I'm using mysql.

I want to know where I put $image to display normally

Here is the Code:

<?php

include 'conn.php';

if(isset($_GET['id']))

    {



$get_cod =  mysqli_real_escape_string($con, $_GET['id']); // GET ID FROM BROWSER

$img = mysqli_query($con,"SELECT * FROM image_user WHERE id_user ='$get_codigo'"); // TABLE QUERY USING FK


$num_rows = mysqli_num_rows($img);

    if($num_rows > 0)
    {
        while($data = mysqli_fetch_assoc($img))
    {
        $image = $data['image_user']; // I WANT TO GET THE BLOB IMAGE FROM DATABASE THAT WAS INSERTED NORMALLY USING THE FILE READER FROM THE NAVIGADOR IN PHP

    }
}

?>

<html>

<head>

</head>

<body>

<img src="profile.php?id=<?php $get_cod; ?>" width="200" alt="user image" title="image">


</body>

</html>
VitorTech
  • 23
  • 1
  • 1
  • 9
  • 1
    why you are not saving images in directory ? – Hamza Zafeer Jun 25 '16 at 02:43
  • Possible duplicate of [PHP display image BLOB from MySQL](http://stackoverflow.com/questions/20556773/php-display-image-blob-from-mysql) – mferly Jun 25 '16 at 02:51
  • Try looking [here](http://stackoverflow.com/questions/20556773/php-display-image-blob-from-mysql) and/or [here](http://stackoverflow.com/questions/13225726/i-need-my-php-page-to-show-my-blob-image-from-mysql-database). – mferly Jun 25 '16 at 02:51
  • **WARNING**: When using `mysqli` you should be using [parameterized queries](http://php.net/manual/en/mysqli.quickstart.prepared-statements.php) and [`bind_param`](http://php.net/manual/en/mysqli-stmt.bind-param.php) to add user data to your query. **DO NOT** use manual escaping and string interpolation or concatenation to accomplish this because you will create severe [SQL injection bugs](http://bobby-tables.com/) if you ever forget to properly escape something. – tadman Jun 25 '16 at 04:27

1 Answers1

0

With this code

<img src="profile.php?id=<?php $get_cod; ?>" width="200" alt="user image" title="image">

what you are getting is a profile id link not the image. As you have already got the image blob from database it can be displayed this way for a jpeg file

<body>
<?php
    if(isset($image)){
      echo '<img src="data:image/jpeg;base64,'.base64_encode($image) .'" width="200" alt="user image" title="image" />';
    }
?>
</body>

Save this file as a php file

Amit Ray
  • 3,445
  • 2
  • 19
  • 35