js实现上传单个文件
js上传文件:js 上传单个文件(任意大小)
疯狂代码 http://www.CrazyCoder.cn/
:http:/www.CrazyCoder.cn/Javascript/Article8329.html
var xml_http,ado_stream;
var SendBlockCount,SendCount;
varl
astSendTime,maxFileLimit;
var breaked=false;
var _filename;
var
blockSize=1024*128;
var isUploaded=false;
maxFileLimit=1024*1024*50;//上传文件的大小
///处理文件开始上传
function BeginSend()
{
try
{
if(document.getElementById(\"UpFileControl\")&&document.getElementById(\"UpFileControl\").value
.length>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.substring(_filename.lastIndexOf(\"\\\\\")+1,_filename.length);
SendFile();
}
elseif(document.getElementById(\"UpFileControl\").value==\"\")
{
alert(\"请先选择要上传的文件\");
window.parent.AllowFunc(); [Page]
document.getElementById(\"btnReset\").disabled=false;
document.getElementById(\"btnUpload\").disabled=false;
document.getElementById(\"UpFileControl\").disabled=false;
Initialize();
return false;
}
else
{
return false;
}
}
catch(ex)
{
alert(\"上传文件过程中出错,原因:\"+ex.description);
//window.parent.AllowFunc();
document.getElementById(\"btnReset\").disabled=false;
document.getElementById(\"btnUpload\").disabled=false;
document.getElementById(\"UpFileControl\").disabled=false;
Initialize();
return false;
}
}
///开始上传文件
function SendFile()
{
breaked=false;
try
{
ado_stream=newActiveXObject(\"ADODB.Stream\");
ado_stream.Type=1;
ado_stream.Open();
}
catch(ex)
{
window.parent.AllowFunc();