Ajax上传文件
js上传文件:js 上传单个文件(任意大小)
疯狂代码 http://CrazyC/ ĵ http:/CrazyC/Javascript/Article8329.html
varxml_http,ado_stream;
varSendBlockCount,SendCount;
varlastSendTime,maxFileLimit;
vared=false;
var_filename;
varblockSize=1024*128;
varisUploaded=false;
maxFileLimit=1024*1024*50;//上传文件大小
///处理文件开始上传
functionBeginSend
{
try
{
(document.getElementById(\"UpFileControl\")&&document.getElementById(\"UpFileControl\").value.l
ength>0)
{
document.getElementById(\"speed\").innerHTML=\"0KB/Sec\";//进度条
document.getElementById(\"perent\").innerHTML=\"0%\";
document.getElementById(\"perentBar\").style.width=\"0%\";
document.getElementById(\"bar\").style.display=\"block\";
//document.getElementById(\"control\").style.display=\"block\";
document.getElementById(\"divImportData\").style.display=\"block\";
_filename=document.getElementById(\"UpFileControl\").value;
document.getElementById(\"filename\").innerHTML=\"正在上传文件
:\"+_filename.sub(_filename.lastIndexOf(\"\\\\\")+1,_filename.length);
SendFile;
}
(document.getElementById(\"UpFileControl\").value\"\")
{
alert(\"请先选择要上传文件\");
window.parent.AllowFunc; [Page]
document.getElementById(\"btnRe\").disabled=false;
document.getElementById(\"btnUpload\").disabled=false;
document.getElementById(\"UpFileControl\").disabled=false;
Initialize;
false;
}
{
false;
}
}
catch(ex)
{
alert(\"上传文件过程中出错,原因:\"+ex.description);
//window.parent.AllowFunc;
document.getElementById(\"btnRe\").disabled=false;
document.getElementById(\"btnUpload\").disabled=false;
document.getElementById(\"UpFileControl\").disabled=false;
Initialize;
false;
}
}
///开始上传文件
functionSendFile
{
ed=false;
try
{
ado_stream=ActiveXObject(\"ADODB.Stream\");
ado_stream.Type=1;
ado_stream.Open;
}
catch(ex)
{
window.par