Progress bar with Jquery counting negative

Asked

Viewed 83 times

1

Hello, I use this code to increase the progress bar:

$(function() 
{
    var bar = $('.bar');
    var percent = $('.percent');
    var status = $('#status');

    var upload = $('form').ajaxForm(
    {
        beforeSend: function() 
        {
            status.empty();
        },
        uploadProgress: function(event, position, total, percentComplete) 
        {          
            document.getElementById("progressBarCurrentFile").style.display = 'block';
            var total_perc = total | 0;
            var current_perc = position | 0;
            document.getElementById("progbarFile").innerHTML = Math.floor((current_perc / (total_perc / 100)) * 100) / 100 + '%';
            document.getElementById("progbarFile").style.width = current_perc / (total_perc / 100) + '%';
        },
        complete: function(xhr) 
        {
            location.href = 'home';
        }
    });
});

The problem is that when the file is larger than 2GB he starts to count negative.

Even though I put it on Pho.ini post_max_size = 9999999M and upload_max_filesize = 9999999M

  • You can tell the file size before you send it, right? When you finish climbing, does it give the correct size or does it enter this negative number? I mean, the final size gets smaller than the original?

  • @Daniel Yes, he arrives without any loss.

  • So don’t just consider this negative number as 0? Then you make proportional to 100% with the file size, it gives in the same.

  • @Daniel No, why does it get to -340 times%.

  • So take the first amount you want to get to current_perc and uses it as a minimum value. You can even reduce this total value in your account in all other operations. (current_perc / ((total_perc - minimal_perc) / 100)) * 100) / 100 + '%', drew?

1 answer

0

My idea: you save the first value that comes to the server as current value and use it as your 0.

$(Function() { var bar = $('.bar'); var Percent = $('.Percent'); var status = $('#status'); var first_val, minimal_perc;

var upload = $('form').ajaxForm(
{
    beforeSend: function() 
    {
        first_val = true;
        status.empty();
    },
    uploadProgress: function(event, position, total, percentComplete) 
    {          
        document.getElementById("progressBarCurrentFile").style.display = 'block';
        if (first_val) { 
          minimal_perc = position; 
          first_val = false;
        };
        var total_perc = total | 0;
        var current_perc = position | 0;

        if (current_perc < 0) total_perc -= minimal_perc;

        document.getElementById("progbarFile").innerHTML = Math.floor((current_perc / (total_perc / 100)) * 100) / 100 + '%';
        document.getElementById("progbarFile").style.width = current_perc / (total_perc / 100) + '%';
    },
    complete: function(xhr) 
    {
        location.href = 'home';
    }
});
  • Even using your code, it continues with values like -147%.

  • Weird, because it’s only with files with 2GB or more.

  • Must be some feature of HTTP that I don’t know about.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.