[英]PECL Uploadprogress Will Not Give Me Upload Progress
I am trying to implement a very basic AJAX upload progress bar using the PECL uploadprogress extension. 我正在尝试使用PECL uploadprogress扩展实现非常基本的AJAX上传进度栏。 I have found this sample code which works across all browsers: http://svn.php.net/viewvc/pecl/uploadprogress/trunk/examples/ .
我发现此示例代码可在所有浏览器上使用: http : //svn.php.net/viewvc/pecl/uploadprogress/trunk/examples/ 。 It uses iframes to write the updates to.
它使用iframe将更新写入。 I would like to get the updates and do some jquery to build a progress bar.
我想获取更新并执行一些jquery来构建进度栏。 Here is my code (I know I did not write in code to account for when the upload ends) client.php:
这是我的代码(我知道我没有写代码来说明上传结束的时间)client.php:
<?php
$id = md5(microtime() . rand());
?>
<!DOCTYPE html>
<html>
<script type="text/javascript" src="jquery-1.7.2.min.js"></script>
<script type="text/javascript">
function getProgress(){
$.get("progress.php", {"ID":'<?php echo $id ?>'}, function(data){
console.log(data);
});
window.setTimeout(getProgress(), 5000);
}
</script>
<body>
<form onsubmit="getProgress()" target="_self" enctype="multipart/form-data" method="post">
<input type="hidden" name="UPLOAD_IDENTIFIER" value="<?php echo $id;?>" />
<label>Select File:</label>
<input type="file" name="file" />
<br/>
<label>Select File:</label>
<input type="file" name="file2" />
<br/>
<label>Upload File:</label>
<input id="submitButton" type="submit" value="Upload File" />
</form>
</body>
</html>
And progress.php: 和progress.php:
<?php
if (function_exists("uploadprogress_get_info")) {
$info = uploadprogress_get_info($_GET['ID']);
} else {
$info = false;
}
$progress = ($info['bytes_uploaded']/$info['bytes_total'])*100;
echo $progress;
I error out and all that prints is 0's. 我错了,所有打印的都是0。 Any ideas?
有任何想法吗?
Try replacing 尝试更换
$progress = ($info['bytes_uploaded']/$info['bytes_total'])*100;
with 与
$progress = ($info['bytes_uploaded']*100)/$info['bytes_total'];
Both $info['bytes_uploaded']
and $info['bytes_total']
are integers, so division is not a float but is rounded down to a integer. $info['bytes_uploaded']
和$info['bytes_total']
都是整数,因此除法不是浮点数,而是四舍五入为整数。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.