title: How to Store and Retrieve Image in SQL Server VARBINARY(MAX) datatype
body: <p>I have saved an image in SQL DB, Image field of varbinary(max) datatype in the following way.</p>
  
  <pre><code>$image = "baby.jpg";
  $type = pathinfo($image, PATHINFO_EXTENSION);
  $data = file_get_contents($image);
  $base64 = 'data:image/' . $type . ';base64,' . base64_encode($data);
  $insert = "insert into logoType(image)values(?)";
  $param = array($base64);
  $sql = sqlsrv_query($dbhandle, $insert, $param ) or die( print_r(sqlsrv_errors()) ); 
  </code></pre>
  
  <p>The insertion part is successful. Now, how can I retrieve the saved image from database and display it in webpage using php. I have tried the following method, but kept getting the error message, "The image cannot be displayed because it contains errors."</p>
  
  <pre><code>header('Content-Type: image/x-bmp');
  echo $image;
  </code></pre>
  
  <p>How can an image be displayed in webpage using php with the data stored in db?. Please Guide. Thanks in advance.</p>