html和java脚本文件都在同一页面上
与之对应的HTML代码是:
<body>
<div id="outer_pog">
<div id="inner_pog">
</div>
</div>
<form action="index.php" method="post" id="myform" enctype="multipart/form-data" target="hidden_frame">
<input type="hidden" value="myform" name="<?php echo ini_get("session.upload_progress.name"); ?>" />
<input type="file" name="userfile" /> <br/>
<input type="submit" value="start upload" />
</form>
<iframe name="hidden_frame" style="display: none;"></iframe>
<span></span>
</body>
javascript代码是:
$(function(){
$('#myform').submit(function(e){
$.get('progress.php',function(dt){
$('span').html(dt);
setTimeout(prog,1000);
});
})
});
function prog(){
$.get('progress.php',function(dt){
$('span').html(dt);
if(dt<100)
{
setTimeout(prog,1000);
}
});
}
当我运行这个时,我总是得到100回报,当我在netbean值中调试它时 $ _SESSION [$ key]总是数组[0]。
php代码,即progress.php,如下:
<?php
session_start();
$key= ini_get("session.upload_progress.prefix")."myform";
if(!empty($_SESSION[$key])){
$cur=$_SESSION[$key]['bytes_processed'];
$tot=$_SESSION[$key]['content_length'];
echo $cur<$tot ? ceil($cur/$tot*100) : 100;
}
else
echo 100;
?>