Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $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;
- $imagen = addslashes($imagen);
- $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);
- }
Add Comment
Please, Sign In to add comment