title: echo BLOBs from database (utf-8)
body: <p>I'm currently working on a web-app with a utf-8 MYSQL database. There are some images saved as BLOBs which I need to display. <br/>
  In all my naivety i thought it would just be something like that:</p>
  
  <pre><code>if($image = $result-&gt;fetch_object())
  {
      header('Content-Type: {$image-&gt;mimetype}');
      echo $image-&gt;data;
  }
  </code></pre>
  
  <p>Which doesn't work. To me it seemed like the image-data is converted to utf-8. So I thought I simply do a dirty hack like</p>
  
  <pre><code>echo utf8_decode($image-&gt;data);
  </code></pre>
  
  <p>... again without any luck. <br/>
  After that I removed the header(...) call to compare the binary result against</p>
  
  <pre><code>echo file_get_contents('sameImageAsInDatabase.jpg');
  </code></pre>
  
  <p>And there are some tiny differences</p>
  
  <p>file_get_contents(...) - works:</p>
  
  <blockquote>
    <p>ÿØÿàJFIFddÿìDuckyPÿá ¨http://ns.adobe.com/xap/1.0/ Â© 2010 Boston University all rights reserved ÿîAdobedÀÿÛ„     ÿÀÌÙÿÄì  !1AQ"aq‘¡2#±ÁÑBRbr‚’3$ðáñ¢²CS%Òcƒ4Âs“£³DT&amp; dt„5ÃÓ”EU6¤´ÔuV'âòÄ…W!1AQaq"ð‘¡±ÁÑ2BRáb#3ñr‚’¢²ÂCS$Òc4sƒ“³%â£Td5òDÿÚ?©Ÿ”²XãÆ6z:¿üWöyíÄTš/_þ+ÿXà¨P0Ž&amp;Y?¬q·+ûõEXªÌ?ß?»Qý¸*ƒ­Ãªÿ8*À3ï¯Y«ï?·X¬¿ñŸÝ¨œF¡t†GÌ¦‘I,àµ?£&lt;ÉÒ.=·¿_¦ˆ<code>º@s-¤Óé</code>p®d¨vÝ—¿ôÒ6• E%äú`wÒ9ÇØ×Ç;ÑTsé‡oÒFÅciBÕìxÇÛÝ®ÒÇâ0Òƒ‡fX/Û¾¼jsÖêÁâ2t Åí¨q–íÇ¶b?@r (ø_fî§jxÌÿ·¶F¿Ã;8ÿÝ¤Ï‘šOúX5°¢þÙÇþèßdÿ¥ƒS ³Û{9Ïå3ñêIÿKªAD%›µöf÷fZŽRÉÿK¹"päso«l;{¸6¶Áå¶‚òÅçsÔfÔâM#í@bau·FD ¨V {zÙüÔ‡úGöâýLJ ¦¼¼5­Ä‚¿Ê?·R(nîùÜH¤n ‘Dnnûù¬ß·P¡±suÿÄI_çŸÛ‰« 7Tÿ¼K_çœF Òl\ÜÇ“ÙæoÛ‚¡@3>_Þ$÷ëoÛˆ¨´Aÿ31ûÌ™sÖpUFnn?ø™s&lt;5ŸÛ‚ ƒ>fæŸ÷‰&lt;‹Û‚¬šóñëÉŸòÏíÁˆQëÏÿÄIîÔpU…¦¸¹§–âN5 1ý¸*ÈhRë/ïývý¸š…u®™=žvý¸*ÂŒ!ÖW•ek™‹åF¥GÇB†æ|¹”ø‚çá‚¬ƒ ÄõÎâPyùš‡</p>
  </blockquote>
  
  <p><br/>
  database - doesn't work:</p>
  
  <blockquote>
    <p>ÿØÿàJFIFddÿìDuckyPÿá ¨http://ns.adobe.com/xap/1.0/ Â© 2010 Boston University all rights reserved ÿîAdobedÀÿÛ?     ÿÀÌÙÿÄì  !1AQ"aq?¡2#±ÁÑBRbr??3$ðáñ¢²CS%Òc?4Âs?£³DT&amp; dt?5ÃÓ?EU6¤´ÔuV'âòÄ?W!1AQaq"ð?¡±ÁÑ2BRáb#3ñr??¢²ÂCS$Òc4s??³%â£Td5òDÿÚ?©??²XãÆ6z:¿üWöyíÄT?/_þ+ÿXà¨P0?&amp;Y?¬q·+ûõEXªÌ?ß?»Qý¸*?­Ãªÿ8*À3ï¯Y«ï?·X¬¿ñ?Ý¨?F¡t?GÌ¦?I,àµ?£&lt;ÉÒ.=·¿_¦?<code>º@s-¤Óé</code>p®d¨vÝ?¿ôÒ6? E%äú<code>wÒ9ÇØ×Ç;ÑTsé?oÒFÅciBÕìxÇÛÝ®ÒÇâ0Ò??fX/Û¾¼jsÖêÁâ2t Åí¨q?íÇ¶b?@r (ø_fî§jxÌÿ·¶F¿Ã;8ÿÝ¤Ï??OúX5°¢þÙÇþèßdÿ¥?S ³Û{9Ïå3ñêIÿKªAD%?µöf÷fZ?RÉÿK¹"päso«l;{¸6¶Áå¶?òÅçsÔfÔâM#í@bau·FD ¨V {zÙüÔ?úGöâýLJ ¦¼¼5­Ä?¿Ê?·R(nîùÜH¤n ?Dnnûù¬ß·P¡±suÿÄI_ç?Û?« 7Tÿ¼K_ç?F Òl\ÜÇ?ÙæoÛ?¡@3&gt;_Þ$÷ëoÛ?¨´Aÿ31ûÌ?sÖpUFnn?ø?s&lt;5?Û? ?&gt;fæ?÷?ÍGXÔ</code>?Ü?Ì?Þíûq5aFk©qJüÔ?×?· Ò?î³¥Ä??5Û?©@MÍ×üiôíÁP us?3Ëìó?Û?¡@1qÿÄKìóÛ?¤?ù??ÿ¼IýsûpT(¯sÇæ$>vý¸?lÜ\</p>
  </blockquote>
  
  <p>Anyone knows what's going on?</p>