-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

Community
  • 1
  • 1
Moon
  • 19,518
  • 56
  • 138
  • 200
  • Which mime-type has the image? – hakre Feb 25 '12 at 03: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 – Moon Feb 25 '12 at 03:07
  • And where do you want to display the image? You can just base64 encode the binary string and then ``. – hakre Feb 25 '12 at 03:10
  • i did it, its not working. i did this '' check the out put at http://moon.pk/sad/ – Moon Feb 25 '12 at 03: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. – hakre Feb 25 '12 at 03:19
  • then how.. please elaborate i am completely new to byte[]s & varbinary & all – Moon Feb 25 '12 at 03:21
  • The code when you store the data to the database is broken. Check that code. But I'm not fluent in that programming language so I can't you help further. – hakre Feb 25 '12 at 03:24
  • you mean, i am doing something wrong while INSERTING the data... – Moon Feb 25 '12 at 03:25
  • Absolutely. `System.Byte[]` is the string inserted into the database and that smells like C#. – hakre Feb 25 '12 at 03:26
  • you are good at smelling, i got the bug, before sending the image i am not properly converting it to the correct data type cuz i don't know which data type to send here. – Moon Feb 25 '12 at 03:32
  • yeah, but my conversion is making the byte data so much bigger that it is taking too much time – Moon Feb 25 '12 at 03:57
  • well it normally makes not much sense to store large images in the database *and* to pass them to the client as data-URIs. – hakre Feb 25 '12 at 03:59
  • theoretically, images sized 90KB(min) to 115KB(max) were supposed to be transferred to MySQL DB and the web-page was supposed to stream the received images over the internet, if this functionality would have worked, i would have built a great application on it. But now i gotta reduce the size somehow – Moon Feb 25 '12 at 04:03
  • instead of '' can i have byte[] or something for byte array here. And please post it as an answer so that i accept it. – Moon Feb 25 '12 at 04:16
  • dude just post anything as answer i want to accept. – Moon Feb 25 '12 at 04:26

2 Answers2

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.

hakre
  • 193,403
  • 52
  • 435
  • 836
-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;">';

Vijay Balan
  • 51
  • 1
  • 2