test.htm Upload File Table Single Page Code:
// Upmit function function btn_send.onclick () {if (filename.value == ") {alert (" The file does not exist, or the file content is empty. "); Return false;} // Create an Ado-stream object VAR ADO_STREAM = New ActiveXObject ("AdoDb.Stream"); // Create an XML document containing the default header information and root node VAR XML_DOM = New ActiveXObject ("msxml2.domdocument"); XML_DOM.LOADXML (' Xml Version = "1.0 "?>
// Send the XML document to the web server var xmlhttp = new activityXObject ("Microsoft.xmlhttp"); XMLHTTP.Open ("post", "./ Test.asp", false); xmlhttp.send (XML_DOM); // Display the information returned by the server div_message.innerhtml = xmlhttp.responseText;} script> Test.asp upload file handler code:
<% @ Language = vbscript%> <% OPTION Explicit Response.expires = 0 'Defines variables and objects. DIM ADO_STREAM DIM XML_DOM, FILENAME DIM XML_FILE1, XML_FILE2
'Creating a Stream Object Set Ado_Stream = Server.createObject ("AdoDB.Stream")' Create an XMLDOM object from the Request object set XML_DOM = Server.createObject ("msxml2.domdocument") XML_DOM.LOAD (Request)
'Read the file name set XML_File2 = XML_Dom.selectsinglenode ("root / file_name") filename = parseFileName (cstr (xml_file2.nodetyped ")
'Reads nodes containing binary data SET XML_FILE1 = XML_DOM.SELECTSINGLENODE ("root / file_body")
'Open Stream object, wherein the data into ado_stream.Type = 1' 1 = adTypeBinary ado_stream.open ado_stream.Write xml_file1.nodeTypedvalue 'File Save dim filepath if right (server.mappath ( "upload"), 1) <> " / "then filepath = Server.mappath (" upload ") " / " filename else filepath = server.mappath (" upload ") filename end if ado_stream.SaveToFile filepath, 2 '2 = adSaveCreateOverWrite ado_stream.close' destroy the object Set ado_stream = nothing set XML_DOM = Nothing 'Returns the information to the browser Response.write "Upload Successful!" FileName
Function ParsefileName (sfilein) Dim i for i = len (sfilein) To 1 step -1 if INSTR ("/", MID (Sfilein, I, 1)) Then Exit for next parsefilename = MID (Sfilein, i 1, len (sfilein) - i) End function%>