Guest User

Untitled

a guest
Oct 30th, 2018
151
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.52 KB | None | 0 0
  1. $host_name = "localhost";
  2. $database = "base_olx";
  3. $user = "root";
  4. $password = "";
  5.  
  6. $con = mysqli_connect($host_name,$user,$password,$database);
  7.  
  8. $json = json_decode(file_get_contents("php://input"),true);
  9.  
  10.  
  11. //$nombre = $json["nombre"];
  12. $nombre = $json["listaNombres"];
  13. $listaImagen = $json["listaImagen"];
  14. $elIdProdInmueble = $json["idProdInmueble"];
  15.  
  16.  
  17.  
  18.  
  19. $respuesta = array();
  20.  
  21.  
  22. if(isset($listaImagen)){
  23.  
  24. if(is_array($listaImagen)){
  25. $i = 0;
  26. $u = 1;
  27. $f = "foto";
  28. foreach($listaImagen as $imagen){
  29.  
  30.  
  31.  
  32. $na = $nombre[$i];
  33. $f = $f.$u;
  34. $ruta = "../fotos/".$na;
  35. $imagen = addslashes($imagen);
  36. $insertarEnGaleria = "INSERT INTO `galeria`(`url`,
  37. `id_prod_inmu`,`imagen`, `ruta`) VALUES
  38. ('$f','$elIdProdInmueble','$imagen','$ruta')";
  39.  
  40.  
  41. $decodedImagen = base64_decode($imagen);
  42. $return = file_put_contents("../fotos/".$na,$decodedImagen);
  43. $i++;
  44.  
  45.  
  46. //$insertarEnGaleria = "INSERT INTO `galeria`(`url`,
  47. `id_prod_inmu`,`imagen`, `ruta`) VALUES
  48. ('$f','$elIdProdInmueble','$decodedImagen','$ruta')";
  49. $f = "foto";
  50. $u++;
  51. mysqli_query($con,$insertarEnGaleria);
  52.  
  53. }
  54.  
  55. $respuesta["ok"] = "Imagenes agregadas con exitos";
  56. }
  57.  
  58.  
  59. header('Content-Type: application/json');
  60. echo json_encode( $respuesta);
  61. }else{
  62. $respuesta["ok"] = "Hubo un error fatal";
  63. header('Content-Type: application/json');
  64. echo json_encode( $respuesta);
  65. }
Add Comment
Please, Sign In to add comment