The use of multi-file upload xmlhttp

  Now xml technology gradually mature and become a web site to disseminate data and a way of using xmlhttp Below I wrote more than one file upload procedures. Including both client and server in two parts .. 

  This procedure is used xml the realization of its nodes can be stored in the base64 encoding of binary files, the first to include client-generated documents xml again through xmlhttp sent to the server. Below are the clients: 

<html>

  <! – 

  Xmlupload.htm by nine Shenlong 

  Http://www.5ucode.com 

  Xkou@hotmail.com 

//–>

< META   Http-equiv = Content-Type content = "text / html; gb2312 charset ="> 

  <title> XML upload client </ title> 

  Submitted to the asp pages <input type = text id = "postto" size = "30" 

  Value = "http://localhost/up.asp" 

  /> <br> 

  Uploaded to the server path <input value = "\" 

  Type = text id = "postpath" onblur = "if (this.value.charAt (this.value.length-1)! = '\ \') This.value + = '\ \';" /> <br> 

  Configuration file upload: <input type = text value = 5 size = 5 id = "upnum"> <button onclick=displayForm(parseInt(upnum.value));> set </ button> 

  <div Id=div1> </ div> <button onclick=sendfile()> 3.5 </ button> <br /> <br /> return information: 

  <div Id="div_message" style="margin-left:20px;padding:10px;border:1px solid silver;"/> 

  <SCRIPT LANGUAGE="JavaScript"> 

  <! – 

  Function displayForm (i) (/ / display the specified number of textbox 

  If (i <2) i = 2; 

  Var tal = ""; 

  For (a = 1; a <= i; a + +) ( 

  Str = a +. "<input Type=file id='upfile'> <br />"; 

  Tal + = str; 

  ) 

  Div1.innerHTML = tal; 

  ) 

  DisplayForm (2); 

  Function sendfile () ( 

  / / Create objects dom 

  Var xmldom = new ActiveXObject ( "MSXML2.DOMDocument"); 

  Xmldom.async = false; 

  / / Load external xml documents in the same directory with the file under construction for a xml.xml content <root> </ root> 

  Xmldom.load ( "xml.xml"); 

  / / Object the establishment of local ado 

  Var ado = new ActiveXObject ( "ADODB.Stream"); 

  Ado.Type = 1; / / 1 = adTypeBinary ado_stream; 

  Var allfile = document.all ( "upfile"); 

  / / Alert (allfile.length); 

  / / Read cycle textbox 

  For (a = 1; a <= allfile.length; a + +) ( 

  If (allfile [a-1]. Value !=""){ 

  / / Create a file node 

  Var fnode = xmldom.createElement ( "file"); 

  Xmldom.documentElement.appendChild (fnode); 

  Var lastnode = xmldom.documentElement.lastChild; 

  / / File Name 

  Fnode = xmldom.createElement ( "name"); 

  Fnode.text = (postpath.value + allfile [a-1]. Value.replace (/(.*) \ \ / g ,"")); 

  Lastnode.appendChild (fnode); 

  / / Contents 

  Fnode = xmldom.createElement ( "content"); 

  Fnode.dataType = "bin.base64"; 

  Ado.Open (); 

  Ado.LoadFromFile (allfile [a-1]. Value); 

  Ado.Read fnode.nodeTypedValue = (-1); 

  Ado.Close (); 

  Lastnode.appendChild (fnode); 

  ) 

  ) 

  / / Alert (xmldom.xml); 

  Div_message.innerHTML = "Data has send, please wait …."; 

  Var xmlhttp = new ActiveXObject ( "Microsoft.XMLHTTP"); 

  Xmlhttp.open ( "POST" postto.value, false); 

  Xmlhttp.send (xmldom); 

  / / Data will be received into UNICODE text 

  Var info = BytesToBstr (xmlhttp.ResponseBody, "GB2312"); 

  Div_message.innerHTML = info; 

  If (info.charAt (0) == "b") 

  / / If it is empty upload files, access to services end of the folder 

  Info.replace postpath.value = (/ .* by ([a-zA-Z]: \ \ .* \ \) .* / g, "$ 1"); 

  ) 

//–>

  </ SCRIPT> 

  <SCRIPT LANGUAGE=vbscript> 

  Function BytesToBstr (body, Cset) / / will be the data received to UNICODE 

  Dim objstream 

  Set objstream = CreateObject ( "adodb.stream") 

  Objstream.Type = 1 

  Objstream.Mode = 3 

  Objstream.Open 

  Objstream.Write body 

  Objstream.Position = 0 

  Objstream.type = 2 

  Objstream.Charset = Cset 

  BytesTobstr = objstream.ReadText 

  Objstream.Close 

  Set objstream = nothing 

  End function 

  </ Script> 

  Client completed 

  Server is relatively simple: 

  <= 0% Response.Expires 

  'Upload.asp by nine Shenlong 

  'Http://www.5ucode.com 

  'Xkou@hotmail.com 

  Set d = Server.CreateObject ( "ADODB.Stream") 

  Set x = Server.CreateObject ( "MSXML2.DOMDocument") 

  X.load (request) 

  Set r = x.documentElement 

  / / Read cycle node 

  For i = 0To (r.childNodes.length-1) 

  R.childNodes set fn = (i). ChildNodes (0) 

  Set xf = r.childNodes (i). ChildNodes (1) 

  D.Type = 1 

  D.open 

  D.Write xf.nodeTypedValue / / read after write 

  D.SaveToFile fn.text, 2 

  D.close%> 

  <% = Fn.text%> ok! <BR> <% Next 

  Nothing set d = 

  Nothing set x =%% => by <server.mappath (Request.ServerVariables ( "SCRIPT_NAME "))%> execute OK! 

  When using two 3-M upload the documents, the use of 100% cpu, a dummy dead in the current window. Guoyihui but can be completed. 

Bookmark it: These icons link to social bookmarking sites where readers can share and discover new web pages.
  • Digg
  • Sphinn
  • del.icio.us
  • Google
  • DotNetKicks
  • DZone
  • Furl
  • Netvouz

Tags: ,

Releated Articles


0 Comments to “The use of multi-file upload xmlhttp”

No Comments. Send your comment.

Leave a Reply

You must be logged in to post a comment.