diff --git a/Documentation.html b/Documentation.html index fdd519c9ea..dd08e4438f 100644 --- a/Documentation.html +++ b/Documentation.html @@ -3399,11 +3399,16 @@ RewriteRule .* - [F] 2.9 Seeing an upload progress bar

To be able to see a progress bar during your uploads, your server must -have either the APC extension - or the uploadprogress - one. Moreover, the JSON extension has to be enabled in your PHP.

+ have the APC extension, + the uploadprogress + one, or you must be running PHP 5.4.0 or higher. + Moreover, the JSON extension has to be enabled in your PHP.

+

If using APC, you must set apc.rfc1867 to on in your php.ini.

+

If using PHP 5.4.0 or higher, you must set session.upload_progress.enabled + to 1 in your php.ini.

+

Known limitations

diff --git a/js/functions.js b/js/functions.js index 8c3cf665e9..30e5511ce0 100644 --- a/js/functions.js +++ b/js/functions.js @@ -3644,6 +3644,30 @@ function toggleRowColors($start) } } +/** + * Formats a byte number to human-readable form + * + * @param bytes the bytes to format + * @param optional subdecimals the number of digits after the point + * @param optional pointchar the char to use as decimal point + */ +function formatBytes(bytes, subdecimals, pointchar) { + if (!subdecimals) { + var subdecimals = 0; + } + if (!pointchar) { + var pointchar = '.'; + } + var units = ['B', 'KiB', 'MiB', 'GiB']; + for (var i = 0; bytes > 1024 && i < units.length; i++) { + bytes /= 1024; + } + var factor = Math.pow(10, subdecimals); + bytes = Math.round(bytes * factor) / factor; + bytes = bytes.toString().split('.').join(pointchar); + return bytes + ' ' + units[i]; +} + /** * Opens pma more themes link in themes browser, in new window instead of popup * This way, we don't break HTML validity diff --git a/libraries/display_import.lib.php b/libraries/display_import.lib.php index 656f5844a0..733f676dbf 100644 --- a/libraries/display_import.lib.php +++ b/libraries/display_import.lib.php @@ -40,19 +40,14 @@ if (empty($import_list)) { - $('#upload_form_status').html('
'); // add the progress bar - var finished = false; var percent = 0.0; var total = 0; var complete = 0; + var original_title = parent && parent.document ? parent.document.title : false; + var import_start; - var perform_upload; - var periodical_upload; - - var request_upload = []; - - perform_upload = function () { + var perform_upload = function () { new $.getJSON( 'import_status.php?id=&', {}, @@ -62,40 +57,91 @@ if ($_SESSION[$SESSION_KEY]["handler"]!="noplugin") { total = response.total; complete = response.complete; - if (total==0 && complete==0 && percent==0) { - $('#upload_form_status_info').html('ajax clock '); - $('#upload_form_status').css("display", "none"); - } else { - $('#upload_form_status_info').html(' '+Math.round(percent)+'%, '+complete+'/'+total); - $('#status').animate({width: Math.round(percent)*2+'px'},150); - } // else + if (total==0 && complete==0 && percent==0) { + $('#upload_form_status_info').html('ajax clock '); + $('#upload_form_status').css("display", "none"); + } else { + var now = new Date(); + now = Date.UTC( + now.getFullYear(), now.getMonth(), now.getDate(), + now.getHours(), now.getMinutes(), now.getSeconds()) + + now.getMilliseconds() - 1000; + var statustext = + formatBytes(complete, 1, PMA_messages.strDecimalSeperator) + + ' ' + + formatBytes(total, 1, PMA_messages.strDecimalSeperator); - if (finished==true) { - $('#importmain').css('display', 'none'); - $('#import_form_status').css('display', 'inline'); - $('#import_form_status').html('ajax clock '); - $('#import_form_status').load('import_status.php?message=true&'); // loads the message, either success or mysql error - + if ($('#importmain').is(':visible')) { + // show progress UI + $('#importmain').hide(); + $('#import_form_status') + .html('
ajax clock
') + .show(); + import_start = now; + } + else if (percent > 9) { + // calculate estimated time + var used_time = now - import_start; + var seconds = parseInt(((total - complete) / complete) * used_time / 1000); + var minutes = parseInt(seconds / 60); + seconds %= 60; + var estimated_time; + if (minutes > 0) { + estimated_time = '' + .replace('%MIN', minutes).replace('%SEC', seconds); + } + else { + estimated_time = '' + .replace('%SEC', seconds); + } - } // if finished - else { - window.setTimeout(perform_upload, 1000); - } + statustext += '

' + estimated_time; + } - } - ); + var percent_str = Math.round(percent) + '%'; + $('#status').animate({width: percent_str}, 150); + $('.percentage').text(percent_str); - } - window.setTimeout(perform_upload, 1000); + // show percent in window title + if (original_title !== false) { + parent.document.title = percent_str + ' - ' + original_title; + } + else { + document.title = percent_str + ' - ' + original_title; + } + $('#statustext').html(statustext); + } // else + + if (finished == true) { + if (original_title !== false) { + parent.document.title = original_title; + } + else { + document.title = original_title; + } + $('#importmain').hide(); + $('#import_form_status') + .html('ajax clock ') + .show(); + $('#import_form_status').load('import_status.php?message=true&'); // loads the message, either success or mysql error + + + } // if finished + else { + setTimeout(perform_upload, 1000); + } + }); + } + setTimeout(perform_upload, 1000); - $('#upload_form_status_info').html('ajax clock '); + $('#upload_form_status_info').html('ajax clock '); $('#upload_form_status').css("display", "none");