title: How to display images in PHP from MSSQL stored as varbinary(MAX) data type
body: <p>As stated in the title, I am having difficultly displaying images.  The code is pulling data from the database and displaying it as a bunch of meaningless characters.  The field is a varbinary(MAX) datatype.  I have tried using a JPEG header, as only JPEG files are allowed to save to the database, and echoing the $row<a href="https://i.stack.imgur.com/Ati1q.jpg" rel="nofollow noreferrer">1</a> variable ($row<a href="https://i.stack.imgur.com/Ati1q.jpg" rel="nofollow noreferrer">1</a> is where the column where the image is stored) but it did not output anything.  Is there a standard way to display binary data from a varbinary(MAX) datatype as an image in PHP?</p>
  
  <p><strong>PHP output</strong>
  <img src="https://i.stack.imgur.com/Ati1q.jpg" alt="enter image description here"></p>
  
  <p><strong>PHP code</strong></p>
  
  <pre><code>&lt;?php
  $servername = "MAINSERVER\SQLEXPRESS";
  $dbname = "SqlFileStream";
  $conn = sqlsrv_connect($servername) or die('Cannot connect to database');
  $stmt = sqlsrv_query($conn, 'SELECT * FROM [VarbinaryTest]') or die(print_r( sqlsrv_errors(), true));
  while ($row = sqlsrv_fetch_array($stmt))
  {
  echo '&lt;br /&gt;';
  echo 'Model: '.$row['model'];
  header('Content-type: image/JPG');
  echo $row['Data'];
  }
  sqlsrv_free_result($stmt);
  ?&gt;
  </code></pre>