Search code examples
phpimagevarbinary

PHP retrieve VARBINARY & display as an image


i am

  1. Creating an image with C#
  2. Converting it to Byte[] -------> This is how i am doing it
  3. then Sending it to MySQL and storing it in VARBINARY

the problem is now I don't know how to retrieve it TO display it as an image

$query = mysql_query("SELECT * FROM sad_img WHERE ss_id='1'");
if( mysql_num_rows( $query ) > 0 )
$ui = mysql_fetch_assoc( $query );

and after that i have no clue, what to do. The internet is not providing mch information about this. Please help


Solution

  • You have stored the string System.Byte[] into the database field where you wanted to store the binary data of the image file into. Fix the insert code and put the plain bytes into the database. In PHP then encode it as base64 to output it:

    <img src="data:image/jpeg;base64,<?php echo base64_encode($ui['screenshot']);?>" />
    

    This should do the job.