我正在尝试实现带有进度条的上传功能,我安装了uploadprogress pecl插件,如果表单中的操作导向upload.php
,上传工作得非常完美,但如果使用其他名称,上传将停止。
如果名称不是upload.php
,输出仅为“100”(可以通过下面的getprogress.php文件查看原因)这是表单:(此版本可用,因为文件是upload.php)
<form method="post" action="/test/upload.php" enctype="multipart/form-data" id="upload-form" target="upload-frame">
<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>
<div style="float:left;width:100%;">
<div id="progress-bar"></div>
</div>
<iframe id="upload-frame" name="upload-frame"></iframe>
这是jQuery:
<script>
(function ($) {
var pbar;
var started = false;
$(function () {
$('#upload-form').submit(function() {
pbar = $('#progress-bar');
pbar.show().progressbar();
$('#upload-frame').load(function () {
started = true;
});
setTimeout(function () {
updateProgress($('#uid').val());
}, 1000);
});
});
function updateProgress(id) {
var time = new Date().getTime();
$.get('../uploadprogress/getprogress.php', { uid: id, t: time }, function (data) {
var progress = parseInt(data, 10);
if (progress < 100 || !started) {
started = progress < 100;
updateProgress(id);
}
started && pbar.progressbar('value', progress);
});
}
}(jQuery));
</script>
这是文件 getprogress.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, 1);
}
else {
// If there is no data, assume it's done
echo 100;
}
}
?>
我花了大约5个小时来尝试弄清楚为什么,但是我无法找到原因。非常希望能得到帮助。
upload.php
的名称以及表单中的upload.php
值重命名,它就完全无法工作了吗? - Jackuploading.php
,则从getprogress.php
输出的结果始终为100。如果名称为upload.php
,则输出为实际上传的百分比值。 - JimmyBanksupload.php
重命名为uploading.php
,而不仅仅是更改表单值,对吗? - Jack