Progress bar with JQuery counting negative

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 it starts counting negative.

Even putting pho.ini post_max_size = 9999999M and upload_max_filesize = 9999999M

    
asked by anonymous 27.03.2017 / 17:46

1 answer

0

My idea: you save the first value that the server arrives as current value and use it as if it were 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';
    }
});
    
27.03.2017 / 22:10