[英]How to save a picture in database sent from android by base64 encoding through PHP?
I am doing a project a part of which includes sending captured image to server. 我正在做一个项目,其中一部分包括将捕获的图像发送到服务器。 I am using 000webhost as my server.
我将000webhost用作服务器。 From my android app I capture an image and send it to server through PHP.
从我的Android应用程序中,我捕获图像并通过PHP将其发送到服务器。 Help me please with any available resource/link/code/example how to save the picture in database.
请提供任何可用的资源/链接/代码/示例来帮助我,如何将图片保存在数据库中。 So I can apply several operation or queries on that.
因此,我可以对此应用几个操作或查询。 For checking my app temporarily I have aploaded pictures which are being saved in a folder of my server.
为了临时检查我的应用程序,我加载了图片,并将其保存在服务器的文件夹中。 The code follow, doing this job:
代码如下,完成这项工作:
` `
// connecting to db
$db = new DB_CONNECT();
error_reporting(E_ALL);
if(isset($_POST['ImageName'])){
$imgname = $_POST['ImageName'];
$imsrc = base64_decode($_POST['base64']);
$fp = fopen($imgname, 'w');
fwrite($fp, $imsrc);
if(fclose($fp)){
echo "success uploading image";
}else{
echo "Error uploading image";
}
}
?>`
You can save the image path in the data base or you can save the base64 itself, as a base64 is a string. 您可以将图像路径保存在数据库中,也可以保存base64本身,因为base64是字符串。 Note that a base64 is a long string, so have that in mind when you create the column to save that info.
请注意,base64是一个长字符串,因此在创建用于保存该信息的列时请记住这一点。 You can also see this .
您也可以看到此 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.