PHP retrieve VARBINARY & display as an image

六眼飞鱼酱① 提交于 2020-01-17 14:56:12

问题


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


回答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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!