-1

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

15
  • Which mime-type has the image? Commented Feb 25, 2012 at 3:04
  • image/jpeg but as i am only generating JPGs so i don't need to store it anywhere, i will explicitly mention it when it comes times to mention, anything else like the width\height of image, title\caption will all be explicit mentions in the php code Commented Feb 25, 2012 at 3:07
  • And where do you want to display the image? You can just base64 encode the binary string and then <img src="data:image/jpeg;base64,YOURENCODEDBINARYDATA" />. Commented Feb 25, 2012 at 3:10
  • i did it, its not working. i did this '<img src="data:image/jpeg;base64,<?php echo $ui['screenshot'];?>" />' check the out put at moon.pk/sad Commented Feb 25, 2012 at 3:17
  • That outputs the following URI: data:image/jpeg;base64,System.Byte[] - obviously this can't work ;) You need to debug your code how you store the binary data into the db, this looks more like the name of the object. Commented Feb 25, 2012 at 3:19

2 Answers 2

2

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.

Sign up to request clarification or add additional context in comments.

Comments

-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;">';

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.