2

I have image in ImageView that is selected by the user ... how can i insert it to mysql database table using php?

can anyone help me with that.

the type of column that i want image to save on it is Blob.

FinalDark
  • 1,758
  • 1
  • 16
  • 26
  • @jtheman imageView.buildDrawingCache(); bmIcone = imageView.getDrawingCache(); ByteArrayOutputStream stream = new ByteArrayOutputStream(); bmIcone.compress(Bitmap.CompressFormat.PNG, 90, stream); byte [] byte_arr = stream.toByteArray(); String image_str = Base64.encodeBytes(byte_arr); namevaluepair.add(new BasicNameValuePair("image",image_str)); php code $base= $_REQUEST['image']; $buffer = base64_decode($base); – FinalDark Feb 10 '13 at 12:48

2 Answers2

5

OK that i found a solution for my question

code in java assuming that the image is already converted to bitmap:

        ByteArrayOutputStream stream = new ByteArrayOutputStream();
        bmIcone.compress(Bitmap.CompressFormat.PNG, 90, stream);
        byte[] byte_arr = stream.toByteArray();
        String image_str = Base64.encodeBytes(byte_arr);
        namevaluepair.add(new BasicNameValuePair("image", image_str));

in server :

$base= $_REQUEST['image'];
    $buffer = base64_decode($base);

    $buffer = mysql_real_escape_string($buffer);

then inserting the $buffer to table blob column type

FinalDark
  • 1,758
  • 1
  • 16
  • 26
0

First, you will have to call your php in android. Many answers already exist on this topic:

To answer your question, this tutorial teaches you how to write your php to store images in MySQL:

Community
  • 1
  • 1
Barney
  • 2,309
  • 3
  • 21
  • 37
  • thx for your help but the tutorial u gave it to me is for html page. android is different i think.. what i am doing right now is converting the ImageView to a bitmap and then convert the bitmap to String by encoding it using base64 ,then send it to php and decode it ... the problem is how can i insert it into table after decoding it? ... or is there any different solution for inserting image to mysql tables? – FinalDark Feb 08 '13 at 13:03