简体   繁体   English

使用android和php存储到mysql的图像

[英]images stored to mysql using android and using php

this is PHPScript i use to display on the browser images stored in mysql database. 这是PHPScript,我用它在浏览器上显示存储在mysql数据库中的图像。

 <?php if($_SERVER['REQUEST_METHOD']=='GET'){ $id = $_GET['id']; $sql = "SELECT image FROM images WHERE id = '$id' "; $con = mysqli_connect("localhost","root","","othmane"); $r = mysqli_query($con,$sql); $result=mysqli_fetch_array($r); //echo '<img src="data:image/jpeg;base64,'.base64_encode( $result['image'] ).'"/>'; //echo base64_encode( $result['image'] ); header('Content-Type:image/jpeg'); //stripslashes ($result['image']); echo ( $result['image'] ); mysqli_close($con); } ?> 

in mysql database there is some images that i have stored using another Script php, and other images are stored using android application( by converting Bitmap to String and using StringBuilder ). 在mysql数据库中,我使用其他脚本php存储了一些图像,而其他图像则使用android应用程序存储(通过将Bitmap转换为String并使用StringBuilder)。

i can succefly display on the browser all images that have been stored by php Script, but i cannot disolay those who have been stored using android apps, i can just see a little rectangle oon the browser. 我可以在浏览器上成功显示php Script存储的所有图像,但是我不能拒绝使用android应用存储的图像,我只能在浏览器上看到一个小矩形。

显示已使用Android应用存储在mysql中的图像

can you clarify me what is going on ? 你能告诉我发生了什么吗?

php script that is responsable to add image to mysql database via android Application : 负责通过android应用程序将图像添加到mysql数据库的php脚本:

 <?php if($_SERVER['REQUEST_METHOD']=='POST'){ $image = $_POST['image']; $con=mysqli_connect("localhost","root","","othmane")or die(mysqli_error($con)); $sql = "INSERT INTO images (image) VALUES (?)"; $stmt = mysqli_prepare($con,$sql); mysqli_stmt_bind_param($stmt,"s",$image); mysqli_stmt_execute($stmt); $check = mysqli_stmt_affected_rows($stmt); if($check == 1){ echo "Image Uploaded Successfully"; }else{ echo "Error Uploading Image"; } mysqli_close($con); }else{ echo "Error"; } ?> 

yes i found it, to show in the browser all images that have been stored in mysql by an android apps, we have to use : echo base64_decode( $result['image'] ); 是的,我找到了它,要在浏览器中显示由android应用存储在mysql中的所有图像,我们必须使用: echo base64_decode( $result['image'] ); and for images that have been saved other way, we have to use just echo ( $result['image'] ); 对于以其他方式保存的图像,我们只能使用echo ( $result['image'] );

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

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