FinalDark
FinalDark

Reputation: 1748

Android: how to upload image in mysql using php

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.

Upvotes: 2

Views: 8510

Answers (2)

FinalDark
FinalDark

Reputation: 1748

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

Upvotes: 4

Barney
Barney

Reputation: 2373

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:

Upvotes: 0

Related Questions