I use these two methods to try to insert an image to a database from an Android application, my problem is that the images are not inserted in the database, the webservices if it works because I use it to do tests in HTML, the one that does not work is that of the app, says that the code is obsolete, and does not compile.
<?php
include ("conexion.php");
$imagp= base64_decode($_POST['imgP']);
$imgv= base64_decode($_POST['imgV']);
$nombre=$_POST['nombre'];
$query = "INSERT INTO imagen (imgP,imgV,nombre ) VALUES ('$imagp','$imgv','$nombre')";
try {
$resultado = $conexion->query($query);
$resultado = array();
$resultado["success"] = false;
echo json_encode($resultado);
} catch (Exception $e) {
echo $e ;
}
if ($resultado){
echo " se inserto";
}
else{
echo "no se inserto";
}
?>
This is the one that tries to use to send the bitmap, but it is obsolete, the code is not mine.
private void enviar() throws IOException {
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost("http://192.168.100.110/SS/agregar.php");
Bitmap bm = BitmapFactory.decodeFile(mapa);
ByteArrayOutputStream stream = new ByteArrayOutputStream();
bm.compress(Bitmap.CompressFormat.JPEG, 100, stream);
byte[] byteArray = stream.toByteArray();
List<BasicNameValuePair> nameValuePairs = new ArrayList<BasicNameValuePair>();
nameValuePairs.add(new BasicNameValuePair("nombre", imageName));
nameValuePairs.add(new BasicNameValuePair("igmP",
Base64.encodeToString(byteArray, Base64.DEFAULT)));
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
HttpResponse response = httpclient.execute(httppost);
}