Собственно сам скрипт:
Код: Выделить всё
var tid;
progress = function(){
$.ajax({
url: '/upload_progress.php',
dataType: 'json',
success: function(data){
if(data.percent) {
$('.progress-bar').width(
Math.ceil(data.percent)+'%';
);
$('.progress-bar').text(Math.ceil(data.percent)+'%');
$('.formbody').hide();
$('.progress').show();
}
}
});
};
$(document).ready(function () {
$('form').ajaxForm({
type: 'POST',
success: function () {
clearInterval(tid);
$('.formbody').hide();
$('.progress').hide();
$('.result').show();
},
beforeSubmit: function () {
tid = setInterval(progress, 100);
}
});
});
Код: Выделить всё
<?php
session_start();
$percent = 0;
$data = array();
if(isset($_SESSION['upload_progress_test']) and is_array($_SESSION['upload_progress_test'])) {
$percent = ($_SESSION['upload_progress_test']['bytes_processed'] * 100 ) / $_SESSION['upload_progress_test']['content_length'];
$percent = round($percent,2);
$data = array(
'percent' => $percent,
'content_length' => $_SESSION['upload_progress_test']['content_length'],
'bytes_processed' => $_SESSION['upload_progress_test']['bytes_processed']
);
}
echo json_encode($data);
?>