Images broken when showing

0

Hello good afternoon someone could tell me because some images are broken but others are not

this is my ajax

$('#cargueArchivo').click(function(){
    if($('#imagen').val() != "") {
    var archivo = $('#imagen')[0].files[0];
    var nombre = archivo.name;
    var tipo = $('#imagen').val().substring($('#imagen').val().lastIndexOf(".") + 1).toLowerCase();
    var tamano = archivo.size;

    if(tipo == "jpg" || tipo == "png" || tipo == "gif") {
        if(tamano < 5242880) {
            var formData = new FormData();
            formData.append('archivo',archivo);
            formData.append('nombre',nombre);
            var urlImagen = "" + nombre;


            $.ajax({
                url:'php/dataBase.php',
                type:'POST',
                cache:false,
                data:{action:"guardarRegistro",imagen:urlImagen,imagenText:$("#image_text").val()}

            }).done(function(response) {
                if(response == -1) {
                    alert("No es posible guardar la imagen en estos momentos. Por favor, inténtelo más tarde.");
                } else {

                    $.ajax({
                        url: 'php/upload.php',
                        type: 'POST',
                        data: formData,
                        cache: false,
                        contentType: false,
                        processData: false

                    }).done(function(response) {

                        if(response == -1) {
                            alert("No es posible subir la imagen en este momento. Por favor, actualizar imagen más tarde.");
                        } else {

                        }
                    });
                }
            });

        } else {
            alert("El tamaño de la imagen no debe exceder de 1 MB.");
        }
    } else {
        alert("El tipo de la imagen no es permitido. Tipos permitidos: .jpg, .png, .gif.");
    }

} else {
    alert("Por favor, seleccione una imagen.");
}



$.post("php/imagen_actualiza.php", function(data){
    $(".showImage").html(data);
});
    
asked by JSACTM Music 02.10.2018 в 18:50
source

1 answer

1

The problem you have is that in the Database you have a name of the image very different from the one you have in your image folder, that is, in your database you have the image with the name error2.png but it's actually called 030102018155510error2.png and when you bring your image names through the ajax it throws a > 404 for the same reason because it does not exist with that name.

Reasons:

1) Someone besides you or yourself changed the name of the image on the BD by hand.

2) Before you did not have the functionality to add that kind of hash in front of the name of the image and you have old data with new data and that's why some of them look like you and others do not.

    
answered by 03.10.2018 / 17:13
source