PHP upload
<?php
if($_SERVER["REQUEST_METHOD"]=="POST"){
include('conexion.php');
//Agregar reporte de marcadores
$datos[0] = trim($_POST['usuario']);
$datos[1] = trim($_POST['fecha']);
$datos[2] = trim($_POST['hora']);
$datos[3] = trim($_POST['tipo']);
$datos[4] = trim($_POST['localizacion']);
$datos[5] = trim($_POST['descripcion']);
$datos[6] = trim($_POST['imagen']);
$decodeImage = base64_decode("$datos[6]");
file_put_contents("pruebas/".datos[0].".JPG", $decodeImage);
$addReporte = mysqli_query($con,"INSERT INTO reporte (usuario,fecha,hora,tipo,localizacion,obsUsuario) VALUES ('$datos[0]','$datos[1]','$datos[2]','$datos[3]','$datos[4]','$datos[5]')").mysqli_error($con);
if ($addReporte != 1) {
//problema al registrar reportes
echo "problem-report".mysqli_error($con);
}else{
echo "report_saved";
}
}else{
echo "Bloqueado por el Administrador";
}
?>
Android
ImageView Fotografia;
String base64;
Fotografia = new ImageView(this);
Bitmap Imagen;
....
Send Information
HttpClient httpClient;
HttpPost httpPost;
httpClient = new DefaultHttpClient();
httpPost = new HttpPost(getString(R.string.registrar_reporte));//url del servidor
try {
List<NameValuePair> nameValuePairs;
//empezamos añadir nuestros datos
nameValuePairs = new ArrayList<NameValuePair>(4);
nameValuePairs.add(new BasicNameValuePair("usuario",Preferencias.getString("ID",""))); //ID de usuario logeado
nameValuePairs.add(new BasicNameValuePair("fecha",Fecha.format(new Date()))); //Fecha de envio
nameValuePairs.add(new BasicNameValuePair("hora",Hora.format(new Date()))); //Hora de envio
nameValuePairs.add(new BasicNameValuePair("tipo",String.valueOf(Tipo))); //Bache,Iluminaria,....
nameValuePairs.add(new BasicNameValuePair("localizacion",Ubicacion)); //Coordenadas GPS
nameValuePairs.add(new BasicNameValuePair("descripcion",repDescripcion.getText().toString())); //Descripcion del usuario
nameValuePairs.add(new BasicNameValuePair("imagen",base64)); //Imagen de reporte
httpPost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
ResponseHandler<String> responseHandler = new BasicResponseHandler();
String response = httpClient.execute(httpPost, responseHandler);
return true;
} catch(UnsupportedEncodingException e){
e.printStackTrace();
}catch (ClientProtocolException e){
e.printStackTrace();
}catch (IOException e){
e.printStackTrace();
}
return false;
Send button
Imagen =((BitmapDrawable) Fotografia.getDrawable()).getBitmap();
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
Imagen.compress(Bitmap.CompressFormat.JPEG,100,byteArrayOutputStream);
base64 = Base64.encodeToString(byteArrayOutputStream.toByteArray(), Base64.DEFAULT);
new Insertar(Reporte_App.this).execute();
Problem!
It is not stored on the server, everything works perfect if I remove it
$datos[6] = trim($_POST['imagen']);
$decodeImage = base64_decode("$datos[6]");
file_put_contents("pruebas/".datos[0].".JPG", $decodeImage);
Everything that carries text to the bdd is stored, my problem is when I try to save the image.