我正在使用 php POST 将文件上传到服务器的网站上工作,并且我正在尝试为上传添加进度条。我遵循了本指南:
http://www.ultramegatech.com/2010/10/create-an-upload-progress-bar-with-php-and-jquery/
它在 ie 和 firefox 中运行良好。但是进度条永远不会在 chrome 中更新。
调用此函数时超时为“500”。
function updateProgress(id) {
var time = new Date().getTime();
// Make a GET request to the server
// Pass our upload identifier as a parameter
// Also pass current time to prevent caching
$.get('progressbar.php', { uid: id, t: time }, function (data) {
// Get the output as an integer
var progress = parseInt(data, 10);
if (progress < 100 || !started) {
var div = document.getElementById('statusfield');
div.innerHTML = progress + '%';
// Determine if upload has started
started = progress < 100;
// If we aren't done or started, update again
updateProgress(id);
}
if (progress > 99) {
var div = document.getElementById('statusfield');
div.innerHTML = 'Komprimerar fil...';
}
// Update the progress bar percentage
// But only if we have started
started && pbar.progressbar('value', progress);
});
}
此函数调用 .php 文件“progressbar.php”,它将上传进度作为百分比数字传回。
进度条.php:
<?php
if (isset($_GET['uid'])) {
// Fetch the upload progress data
$status = uploadprogress_get_info($_GET['uid']);
if ($status) {
// Calculate the current percentage
echo round($status['bytes_uploaded']/$status['bytes_total']*100);
}
else {
// If there is no data, assume it's done
echo 100;
}
}
?>
我已经在 chrome 中测试了代码,并调用了函数“updateProgress”。但它永远不会超过:
$.get('progressbar.php', { uid: id, t: time }, function
有没有人知道可能出了什么问题?
谢谢!