title: convert base64 string to image in php
body: <p>i want to convert image into byte array and save this byte array into my database after that i want to fetch this byte arrar and print on browser</p>
  
  <p>for this i tried to passed an image in base64_encode() function which gives me string this string i passed into base64_decode() function.but image is not showing here is my code
  this is my first file for storing image byte array</p>
  
  <p>` 
  
  <pre><code>    $demo="/9j/4AAQSkZJRgABAQEAYABgAAD/2wBDAAIBAQIBAQICAgICAg";
      $data = base64_decode($demo);
      $host="localhost";
      $db="demo";
      $password="";
      $db_user="root";
      $conn=mysqli_connect($host,$db_user,$password) or die("connection not stablished");
      mysqli_select_db($conn,$db) or die("database not found");
      $temp=mysqli_query($conn,"INSERT INTO imagetable (image)
                  VALUES ('".$data."')");
      if($temp==TRUE)
      {
        echo "image inserted";
      }
      else
      {
      echo "image not inserted";
      }
  </code></pre>
  
  <p>?>
  `
  this is my second file for display image</p>
  
  <pre><code>`&lt;?php
  
  $db = mysqli_connect("localhost","root","","demo"); //keep your db name
  $sql = "SELECT * FROM imagetable WHERE id=2";
  $sth = $db-&gt;query($sql);
  $result=mysqli_fetch_array($sth);
  echo '&lt;img src="data:image/jpeg;base64,'.base64_encode( $result['image'] ).'"/&gt;';
  </code></pre>
  
  <p>?>`</p>
  
  <p>but it doesn't display image at browser instead it give error</p>
  
  <blockquote>
    <p>cannot be displayed because it contains error</p>
  </blockquote>