将Base64 String转换为Image(使用JSON从android发送)并使用PHP在MySQL中保存为BLOB

Stu*_*ent -1 php mysql base64 android json

实际上我在我的android项目中从JSON获取了图像字符串.字符串图像成功传递给使用HTTPPOST.现在,我面临的问题是在php中的mysql数据库中将图像保存为blob类型.如何转换我得到的字符串图像,以便它可以保存为mysql数据库中的blob类型?如果有人知道的方式,请善意的建议.

谢谢.

Ben*_*n D 6

只需base64_decode()数据:

$blob = base64_decode($json_64_encoded_string);
Run Code Online (Sandbox Code Playgroud)

然后将其写入DB.如果您需要帮助从POST数组中获取编码的字符串,请查看PHP json_decode函数:http://php.net/manual/en/function.json-decode.php

$json_obj = json_decode($_POST[post_key]); //replace 'post_key' with whatever you use
$blob = base64_decode($json_obj->blob); //replace 'blob' with whatever you use
Run Code Online (Sandbox Code Playgroud)