简体   繁体   English

Android:如何使用php在mysql中上传图片

[英]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? 我在ImageView中有用户选择的图像...我如何使用php将其插入到mysql数据库表中?

can anyone help me with that. 谁能帮助我。

the type of column that i want image to save on it is Blob. 我要图像保存在其上的列的类型是Blob。

OK that i found a solution for my question 好,我找到了解决我问题的方法

code in java assuming that the image is already converted to bitmap: 假定图像已转换为位图的Java代码:

        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 然后将$ buffer插入表Blob列类型

First, you will have to call your php in android. 首先,您将不得不在android中调用您的php。 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: 为了回答您的问题,本教程教您如何编写php在MySQL中存储图像:

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM