<form action="incertar-proveedor.php" method="post" enctype="multipart/form-data">
    <div class="form-group">
        <label for="recipient-name" class="col-form-label">Nombre:</label>
        <input type="text" class="form-control" name="nombre" id="recipient-name">
    </div>
    <div class="form-group">
        <label for="message-text" class="col-form-label">Email:</label>
        <input type="text" class="form-control" name="email" id="message-text"></input>
    </div>
    <div class="form-group">
        <label for="message-text" class="col-form-label">Telefono:</label>
        <input type="number" class="form-control" name="telefono" id="message-text"></input>
    </div>
    <div class="form-group">
        <label for="message-text" class="col-form-label">Dirección:</label>
        <input type="text" class="form-control" name="direccion" id="message-text"></input>
    </div>
    <div class="form-group">
        <label for="message-text" class="col-form-label">Foto:</label>
        <input type="file" class="form-control" name="fileToUpload" id="fileToUpload"></input>
    </div>
    </div>
    <div class="modal-footer">
        <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
        <button type="submit" class="btn btn-primary"onclick="upload()">Guardar</button>
    </div>
</form>
<script>
    function upload() {
        let file = document.getElementById('fileToUpload');
        let imagen = file.files[0]
        alert("el proceso va a empezar");
        let xhr = new XMLHttpRequest();
        var formData = new FormData();
        formData.append("fileToUpload", file);
        xhr.upload.onprogress = function(event) {
            console.log(`Uploaded ${event.loaded} of ${event.total}`);
        };

        // seguimiento completado: sea satisfactorio o no
        xhr.onloadend = function() {
            if (xhr.status == 200) {
                console.log("Logrado");
            } else {
                console.log("error " + this.status);
            }
        };

        xhr.open("POST", "./incertar-proveedor.php", true);
        xhr.send(formData);
        xhr.onload = () => alert(xhr.response);
    }
</script>