问题描述
在表单提交,进度条出现,而getProgress函数被调用。 getProgress检查PHP文件(使用上传进度阿帕奇国防部获取当前的上传进度),并返回一个数字从0到100(即完成)。
After the form submits, the progressbar appears, and the getProgress function is called. getProgress check a php file (which uses the uploadprogress apache mod to get the current upload progress) and returns a number from 0 to 100 (which means complete).
确定,我们的想法是,getProgress是自我执行,如果返回的数字不是100。否则,形式不断upload.php的该文件的操作。
这是IM寻找的是什么: http://screenr.com/ByG < - 视频
THIS IS WHAT IM LOOKING FOR: http://screenr.com/ByG <- video.
下面是HTML的部分。
Here is the HTML part.
<form method="post" action="upload.php" enctype="multipart/form-data" id="UploadForm">
<input type="hidden" id="uid" name="UPLOAD_IDENTIFIER" value="<?php echo $uid; ?>">
<input type="file" name="file">
<input type="submit" name="submit" value="Upload!">
</form>
<div id="UploadBarContainer">
<div id="LoadBar"></div>
<div id="ProgressBar"></div>
</div>
下面是jQuery的一部分。 这似乎被打破
Here is the jQuery part. Which seems to be broken
$(function(){
// This flag determines if the upload has started
var started = false;
// Start progress tracking when the form is submitted
$('#UploadForm').submit(function() {
//Update the flag to true.
started = true;
//Hide the form.
$('#UploadForm').hide();
//Show the progress bar.
$('#UploadBarContainer, #LoadBar, #ProgressBar').show();
//Start updating progress after a 2 second delay.
//This is to prevent the getprogress.php assume that upload is complete.
setTimeout(function () {
// We pass the upload identifier to our function
getProgress($('#uid').val());
}, 2000);
});
//Function used to get the current upload progress.
//It should be executed over and over again untill the result is 100.
function getProgress(id) {
//Get the current time.
var time = new Date().getTime();
//Make an ajax request to the server.
$.ajax({
//Pass the data trought GET method.
type: 'GET',
//Get the progress from this php file.
url: 'getprogress.php',
//Pass our upload identifier as a parameter and current time to prevent caching.
data: { uid: id, t: time },
//Get the results.
success: function (data) {
//Get the output as an integer.
var progress = parseInt(data, 10);
//If upload progress is not 100, change bar percentage and update again.
if (progress < 100) {
//Update the progress bar percentage.
//But only if we have started.
$('#ProgressBar').css('width', progress + '%');
//If we aren't done, update again.
getProgress(id);
}
}
});
}
});
就在我情况下,这会有所帮助,这里是呼吁$就要求getprogress.php文件。
Just i case this helps, here is the getprogress.php file called on the $.ajax request.
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;
}
}
任何帮助是AP preciated,我有一个现场演示,但我害怕的是什么,你可以上传。
Any help is appreciated, i have a live demo but i scared about what you could upload.
推荐答案
那么最后我得出的结论是不可能得到这个工作WebKit的浏览器如Opera,Chrome和Safari,而不是等Firefox和Internet Explorer
Well finally i came to the conclusion it is not possible to get this working on webkit browsers such as opera, chrome and safari, not so on firefox and internet explorer.
Webkit内核的浏览器往往会阻止任何阿贾克斯当文件被上传。
Webkit browsers tend to block any ajax while a file is being uploaded.
您可能要检查了这一点: https://bugs.webkit.org/ show_bug.cgi?ID = 23933
You may want to check this out: https://bugs.webkit.org/show_bug.cgi?id=23933
这篇关于我不能更新通过$就对形式的进度提交的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!