问题
i am
- Creating an image with C#
- Converting it to Byte[] -------> This is how i am doing it
- 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
回答1:
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.
回答2:
use this code for base64 type image fileds
<img class="w3-hover-opacity"src="data:image/jpeg;base64,'.base64_encode( $row['Photo'] ).'"
width="120" height="120" onClick="onClick(this)" style="cursor:pointer border-raduis:1px;">';
来源:https://stackoverflow.com/questions/9440759/php-retrieve-varbinary-display-as-an-image