0
I’m using the following code that sends the post with the $_FILE file to a file I called upload.php, which makes use of Amazon’s php sdk. The upload is taking place normally, but I noticed that the progress bar goes to 100% without first having sent the file to my Bucket which causes a certain confusion for the system user.
I am using the following code in jquery:
$("#uploadFiles").submit(function(event) {
//Para evento padrão de submit
event.preventDefault();
//Pega referencia a barra de progresso
var progressBar = $(".progress-bar");
//Busca o form de upload e o retorna como um objeto
var form = document.getElementById("uploadFiles");
var formData = new FormData(form);
$.ajax({
type: 'POST', //Or 'GET',
url: '../funcoes/upload.php',
data: formData,
contentType: false,
processData: false,
xhr: function() {
var xhr = $.ajaxSettings.xhr();
if(xhr.upload){
xhr.upload.addEventListener("progress", function(evt) {
if (evt.lengthComputable) {
progressBar.css("visibility", "visible");
var percentComplete = evt.loaded / evt.total;
var progresso = Math.round(percentComplete * 100) + "%";
//Adiciona texto com progresso na div
//progressBar.empty().append(progresso);
//Aumenta tamanho da div conforme progresso
progressBar.width(progresso);
}
}, false);
}
return xhr;
},
dataType: 'json',
success: function(data) {
//Limpa texto de progresso e volta barra pro inicio
progressBar.empty().width('0%');
//Coloca a barra de progresso invisivel
progressBar.css("visibility", "hidden");
}
});
});
How do I fix it?
This value computed in ajax is from the client to the
upload.php, No?! It is your background that makes the sending of the files.– Renan Gomes
Yes, that’s what I want to know. How will I track the progress that happens in the upload file? 'Cause that’s where I make use of Amazon’s sdk.He uploads it into the Bucket @Renan
– Leandro Silva Campos