我正在尝试为我上传到服务器的多个文件创建进度条!我能够上传文件,但是当我尝试获取上传进度信息时,会话数组为空。请帮忙!!!请在下面找到相关信息: 首先是我上传文件的主要php页面:
********************************************Main.php********************************
<?php session_start();?>//top of the page
<div id = "centerMain" align="center">
<iframe name="targetIframe" src="" style="width:50%;height:30%;position:relative;"></iframe>
<div id="addNewBlock" class="emboss blockPart" style="z-index:50000;padding:2%;position:relative;width:50%;left:25%;top:35%;border:1px solid black;">
<form method="POST" action="handleItemAddition.php" target="targetIframe" enctype = "multipart/form-data" onSubmit="return checkAndStartUpload()">
<!--VERY IMPORTANT:the hidden element should come first before any element within the form--> <input type="hidden" name="<?php echo ini_get("session.upload_progress.name"); ?>" id="hidUpProg" value="upFilesInfo" />
<script type ="text/javascript">
var upProgName = "<?php echo ini_get("session.upload_progress.name"); ?>";
//alert(document.getElementById("hidUpProg").value);
</script>
<div class="stayLeft">Upload Photo:</div><input style="width:40%;" type="file" name = "itemImage[]" id="fileUp" class = "stayRight" multiple/><br/><br/>
<input type="button" id = "closeBut" style="width:20%;" value = "close" onclick="closeBlock()" class="utsaaBut stayLeft"/>
<input type="submit" id = "AddBut" style="width:20%;" value = "Done" class="utsaaBut stayRight"/>
</form>
</div>
</div>
********************************************Main.php********************************
在下面找到javscript函数,它从上面调用onSubmit =“checkAndStartUpload()”
******************************************Javascript function****************************
function checkAndStartUpload()
{
var tmp = document.getElementById("fileUp");
if(tmp.files.length == 0)
{
alert("No file selected. Kindly select a file");
return false
}
$progressPtr = setInterval(handleProgress,50);
return true;
}
var it = 0;
function handleProgress()
{
//alert("handleProgress");
var xmlhttp;
if(window.XMLHttpRequest)
{
xmlhttp = new XMLHttpRequest();
}
else
{
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
//alert("response");
if(xmlhttp.readyState == 4 && xmlhttp.status == 200)
{
//alert("value:"+xmlhttp.responseText["content_length"]);
var res = xmlhttp.responseText;
alert("Response:"+res);
it++;
if(it == 25)
{
it = 0;
clearInterval($progressPtr);
}
}
}
xmlhttp.open("POST","handleProgressValue.php",true);
xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");
xmlhttp.send(upProgName+"=upFilesInfo");
}
******************************************Javascript function*******************
接下来是通过ajax
返回会话值的文件 ******************************************ajax progress return*******************
<?php
$key = ini_get("session.upload_progress.prefix") .$_POST[ini_get("session.upload_progress.name")];
if (!empty($_SESSION[$key])) {
$current = $_SESSION[$key]["bytes_processed"];
$total = $_SESSION[$key]["content_length"];
echo "Current".$current."$total".$total;
//echo $current < $total ? ceil($current / $total * 100) : 100;
}
else {
echo "100"; //IT ALWAYS RETURNS 100 MEANING$_SESSION[$key] IS ALWAYS EMPTY
}
/*session_start();
$key = ini_get("session.upload_progress.prefix").$_POST[ini_get("session.upload_progress.name")];
//var_dump($_SESSION[$key]);
$tmp = $_SESSION[$key];
echo $tmp["bytes_processed"];*/
?>
******************************************ajax progress return*******************
最后,handleItemAddition.php成功上传了图片。 我也禁用了; session.upload_progress.cleanup = On只是为了测试目的,所以如果上传快速完成,它不应该清除值。
我仍然是空阵。
答案 0 :(得分:0)
嘿伙计们抱歉我忘了更新。我有时会修复这个问题。 我把session_start();在所有文件的顶部,但在handleProgressValue.php中,我在更改代码时对其进行了评论,一旦我取消注释它有效。
但是当我上传28个文件时,为什么呢 计数($ _ SESSION [$关键] [ “文件”]) 返回增加值???它首先返回10然后是17,24,28然后$ _SESSION被取消了