how can I upload an image from android to my database but in a column that is longblob?

0

I tried to upload an image to my database but it was inserted in the longblob column but I could not find it here my php code:

$host_name = "localhost";
$database = "base_olx";
 $user = "root";
 $password = "";

$con = mysqli_connect($host_name,$user,$password,$database);

$json = json_decode(file_get_contents("php://input"),true);


//$nombre = $json["nombre"];
 $nombre = $json["listaNombres"];
 $listaImagen = $json["listaImagen"];
 $elIdProdInmueble = $json["idProdInmueble"];




 $respuesta = array();


  if(isset($listaImagen)){

   if(is_array($listaImagen)){
       $i = 0;
       $u = 1;
       $f = "foto";
       foreach($listaImagen as $imagen){



           $na = $nombre[$i];
           $f = $f.$u;
           $ruta = "../fotos/".$na;
           $insertarEnGaleria = "INSERT INTO 'galeria'('url', 
  'id_prod_inmu','imagen', 'ruta') VALUES 
  ('$f','$elIdProdInmueble','$imagen','$ruta')";

           $decodedImagen = base64_decode($imagen);
           $return = file_put_contents("../fotos/".$na,$decodedImagen);
           $i++;


           //$insertarEnGaleria = "INSERT INTO 'galeria'('url', 
   'id_prod_inmu','imagen', 'ruta') VALUES 
   ('$f','$elIdProdInmueble','$decodedImagen','$ruta')";
            $f = "foto";
            $u++;
            mysqli_query($con,$insertarEnGaleria);

       }

        $respuesta["ok"] = "Imagenes agregadas con exitos";
   }


   header('Content-Type: application/json');
   echo  json_encode( $respuesta);
 }else{
  $respuesta["ok"] = "Hubo un error fatal";
   header('Content-Type: application/json');
  echo  json_encode( $respuesta);
 }

and in android that's how I grab the image in a list and send it as a post parameter to the webservices that pass them up.

 Bitmap 
bitmap=
MediaStore.Images.Media.getBitmap(this.getContentResolver(),Uri.fromFile(new 
     File(this.listaDeRutas.get(i))));
                        ByteArrayOutputStream byteArrayOutputStream = new 
    ByteArrayOutputStream();

     bitmap.compress(Bitmap.CompressFormat.JPEG,100,byteArrayOutputStream);
                        String bitMapCodificado = 

   Base64.encodeToString(byteArrayOutputStream.toByteArray()
                ,Base64.DEFAULT);
                        this.listaDeImagenes.add(bitMapCodificado);
                        File laImagen = new File(this.listaDeRutas.get(i));
                        this.ListaDeNombres.add(laImagen.getName());

Well I hope you help me in this situation, maybe my previous code is not what I have to do thank you very much:).

    
asked by David Garcia 31.10.2018 в 00:47
source

0 answers