gpt4 book ai didi

php - 使用后期处理上传进度

转载 作者:太空狗 更新时间:2023-10-29 15:22:51 24 4
gpt4 key购买 nike

我有一个上传表单,用户可以在其中上传文件。上传完成后,文件会进行后期处理,有时上传完成后处理需要 10-15 秒。

上传完成后,进度条为 100%,但如何检测文件何时完成,以便您可以在文件处理时向用户显示“请稍候”标志。.用户可能会认为浏览器已卡住 og 崩溃,因为进度条处于 100% 但什么也没有发生..

最好使用纯 HTML5+javascript 的客户端解决方案,但不是必须的:)

最佳答案

尝试

html

<progress min="0" max="10000"></progress>
<output for="progress"></output>
<output for="progress"></output>
<br />
<table id="results"></table>

js

var len = arr.length // file length
, start = 0 // update progress
, outputs = $("output[for=progress]") // notifications
, progress = $("progress")
, results = $("#results") // post processing
// gif spinner
, spinner = $("<img />", {
"src": "data:image/gif;charset=binary;base64,R0lGODlhEAAQAPIAAP///wAAAMLCwkJCQgAAAGJiYoKCgpKSkiH+GkNyZWF0ZWQgd2l0aCBhamF4bG9hZC5pbmZvACH5BAAKAAAAIf8LTkVUU0NBUEUyLjADAQAAACwAAAAAEAAQAAADMwi63P4wyklrE2MIOggZnAdOmGYJRbExwroUmcG2LmDEwnHQLVsYOd2mBzkYDAdKa+dIAAAh+QQACgABACwAAAAAEAAQAAADNAi63P5OjCEgG4QMu7DmikRxQlFUYDEZIGBMRVsaqHwctXXf7WEYB4Ag1xjihkMZsiUkKhIAIfkEAAoAAgAsAAAAABAAEAAAAzYIujIjK8pByJDMlFYvBoVjHA70GU7xSUJhmKtwHPAKzLO9HMaoKwJZ7Rf8AYPDDzKpZBqfvwQAIfkEAAoAAwAsAAAAABAAEAAAAzMIumIlK8oyhpHsnFZfhYumCYUhDAQxRIdhHBGqRoKw0R8DYlJd8z0fMDgsGo/IpHI5TAAAIfkEAAoABAAsAAAAABAAEAAAAzIIunInK0rnZBTwGPNMgQwmdsNgXGJUlIWEuR5oWUIpz8pAEAMe6TwfwyYsGo/IpFKSAAAh+QQACgAFACwAAAAAEAAQAAADMwi6IMKQORfjdOe82p4wGccc4CEuQradylesojEMBgsUc2G7sDX3lQGBMLAJibufbSlKAAAh+QQACgAGACwAAAAAEAAQAAADMgi63P7wCRHZnFVdmgHu2nFwlWCI3WGc3TSWhUFGxTAUkGCbtgENBMJAEJsxgMLWzpEAACH5BAAKAAcALAAAAAAQABAAAAMyCLrc/jDKSatlQtScKdceCAjDII7HcQ4EMTCpyrCuUBjCYRgHVtqlAiB1YhiCnlsRkAAAOwAAAAAAAAAAAA=="
});
// upload file
var request = function () {
progress.prop("max", len);
s = setInterval(function () {
progress.prop("value", ++start);
outputs.eq(0)
.text("uploading file...")
}, 1)
return $.post("/echo/json/", {
json: JSON.stringify(arr)
})
.then(function (data) {
clearInterval(s)
s = null;
progress.prop("value", len);
outputs.eq(0)
.html("upload complete ! <br />processing response, please wait...")
.next(outputs.eq(1))
.html(spinner);
return data
})
};

request()
.then(function (data) {
// do post upload processing stuff
var process = function() {
var dfd = new $.Deferred();
// processing...
t = setTimeout(function () {
data.forEach(function (res) {
results.append(
$("<tr />", {
"html": $("<td />", {
"html": res.value
})
}))
});
if (results.find("tr").length === len) {
dfd.resolve("complete !")
}
}, 1 + Math.floor(Math.random() * 15000));
return dfd.promise()
};
// do stuff when all post processing complete
process().then(function(complete) {
outputs.eq(0).empty()
.next(outputs.eq(1))
.html(complete);
clearTimeout(t);
t = null;
})
});

jsfiddle http://jsfiddle.net/guest271314/d2szrs20/

关于php - 使用后期处理上传进度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27690326/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com