Monday, May 7, 2012

PHP extension upload progress - returning negative total bytes and time remaining


I'm using the PHP upload progress extension to retrieve information about files being uploaded to my web system. However for files larger than 2GB the total bytes and time remaining fields are being returned as negative numbers.



Apache has been setup to ensure that files of a size up to 3GB can be uploaded to the website. I have tested this and it works. However it is purely the reporting that is coming back incorrectly.



I was wondering if this was anything to do with a limit on the PHP values and what could be done to fix it. I believe the system is using 64bit integers. As the following shows:




echo "PHP_INT_MAX: " . PHP_INT_MAX;
// PHP_INT_MAX: 9223372036854775807



Here's some extra information on how the progress bar works and is installed: http://www.ultramegatech.com/blog/2010/10/create-an-upload-progress-bar-with-php-and-jquery/



To get the information I simply call the extension function:




$status = uploadprogress_get_info($unique_form_id);



Which returns the total bytes, est time remaing, current bytes and more as shown below (with negative total bytes):




array(11) {
["upload_id"]=> string(32) "ec75a30c24177ec1579aea93b56224f2"
["fieldname"]=> string(9) "comp_data"
["filename"]=> string(15) "Size_2-09GB.zip"
["time_start"]=> string(10) "1325851749"
["time_last"]=> string(10) "1325851758"
["speed_average"]=> string(5) "93011"
["speed_last"]=> string(6) "112618"
["bytes_uploaded"]=> string(6) "837105"
["bytes_total"]=> string(11) "-2048166056"
["files_uploaded"]=> string(1) "1"
["est_sec"]=> string(9) "-76260228"
}



Update (6th Jan 2012): I have also contacted the developer of this extension to see if they can share any insight.



Update (9th Jan 2012): Developer of the extension has responded pointing out that there is an existing ticket regarding this issue: https://bugs.php.net/bug.php?id=59918



Update (16th Jan 2012): Have managed to get rid of the negative value being returned by the extension. However the number returned is way off what the actual number of total bytes in comparison to what Windows says it is in the properties window.


Source: Tips4all

1 comment:

  1. Use a float and remove the decimals - this will work for these larger numbers:

    $filesize = filesize($large_file);
    printf(Filesize: %.0f\n", $filesize);


    This answer will confirm if you are using 64bit Integers : how to have 64 bit integer on PHP?

    Note: although there is another answer to that question which seems to indicate that 64bit integers are not available on windows - what OS are you using ?

    ReplyDelete