先奉上代码,再说问题
progress.php
<html>
<head><title>上传演示</title></head>
<body>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script type="text/javascript" src="jquery.js"></script>
<script language="javascript">
var id = new Date().getTime();
var interval = 1;
$(function(){
$("#uploadframe").attr("src","upload.php?id="+id);//返回属性值的函数 ,第一个参数为当前元素的索引值,第二个参数为原先的属性值。
});function getProgress(){//获得进度
$.post(
'getprogress.php',
{progress_key:id},
function(returnHTML){
alert(returnHTML);
var obj = eval("("+returnHTML+")");//eval() 函数可计算某个字符串,并执行其中的的 JavaScript 代码。
if(obj.percent < 100){
setTimeout("getProgress()", interval);//interval间隔
}
$("#progressinner").css("width",obj.percent+"%");
$("#fileSize").html(obj.total);//文件总大小
$("#currentSize").html(obj.current);//已传大小
$("#currentpercent").html(obj.percent+"%");//上传的百分比 }
)
}function startProgress(){//显示进度条
$("#progressouter").css("display","block");//设置进度条为显示
setTimeout("getProgress()", interval);//interval间隔 //setTimeout(代码,时间)多长时间后执行一次括号里面的代码
}</script><iframe id="uploadframe" name="uploadframe" src="" style="border: none;"></iframe>
<br/><br/>
<div id="progressouter" style=
"width: 500px; height: 10px; border: 1px solid red; display:none;"><!--进度条总长-->
<div id="progressinner" style=
"position: relative; height: 10px; background-color: purple; width: 0%; "><!--已上传进度条-->
</div>
文件大小:<div id='fileSize'></div>
已上传:<div id='currentSize'></div>
<div id='currentpercent'></div>
</div></body>
</html>upload.php
<?php $id = $_GET['id']; ?>
<form enctype="multipart/form-data" id="upload_form" action="target.php" method="POST">
  <input type="hidden" name="APC_UPLOAD_PROGRESS" id="progress_key"  value="<?php echo $id?>"/>
  <input type="file" id="test_file" name="test_file"/><br/>
  <input onclick="window.parent.startProgress(); return true;" type="submit" value="上传"/><!--window.parent.startProgress()
当点击上传按钮的时候显示进度条-->
</form>target.php
<?php
set_time_limit(600);//设置最大执行时间
if($_SERVER['REQUEST_METHOD']=='POST') {//判断提交的数据是否是POST方式传来的
  if(move_uploaded_file($_FILES["test_file"]["tmp_name"],
  dirname($_SERVER['SCRIPT_FILENAME'])."/UploadTemp/" . $_FILES["test_file"]["name"])){//UploadTemp文件夹位于此脚本相同目录下
 echo "<p>上传成功!</p>";
  }else{
echo "<p>上传失败0001</p>";
  }
}else{
echo "<p>上传失败0002</p>";
}
?>getprogress.php
<?php
//获得进度
session_start();
if(isset($_POST['progress_key'])) {//isset()在php中用来检测变量是否设置,该函数返回的是个布尔值,即true/false
  $status = apc_fetch('upload_'.$_POST['progress_key']);//获取session中的值
  $data['current'] = $status['current'];
  $data['total'] = $status['total'];
  $data['percent'] = intval(($status['current']/$status['total'])*100);//intval讲变来那个转化为整型 (已传的/所有的)*100
  echo json_encode($data);////输出给用户端页面里的ajax调用
}
?>现在的问题就是,有的时候可以获取到上传的进度,但是有的时候就不能获取到,郁闷啊,还是随机的,让我想不明白,而且有的时候一个同意文件,第一次能获取到上传的进度,再传就不可以了,为什么??