XML skills file Upload 3

Source: Internet
Author: User
The following sample code of the client applies Stream and MSXML objects to complete file upload. HTMLHEADTITLEFileSend/TITLE/HEADBODYINPUTid = btn_sendname = "btn_send" type = buttonvalue = "FILESEND" DIVid = div_mess Client

The following sample code applies Stream and MSXML objects to complete file upload.

<HTML>
<HEAD> <TITLE> File Send </TITLE> </HEAD>
<BODY>
<INPUT id = btn_send name = 'btn _ send' type = button value = 'File send'>
<DIV id = div_message> Ready
</BODY>
</HTML>

<Script language = JavaScript>

// Upload function
Function btn_send.onclick ()
{
// Create an ADO-stream object
Var ado_stream = new ActiveXObject ('adodb. stream ');

// Create an XML document containing the default header information and the root node
Var xml_dom = new ActiveXObject ('msxml2. domdocument ');
Xml_dom.loadXML (' ');
// Specify the data type
Xml_dom.documentElement.setAttribute ('xmlns: dt ', 'urn: schemas-microsoft-com: PES ypes ');

// Create a new node and set it as a binary data node
Var l_node1 = xml_dom.createElement ('file1 ');
Rochelle node1.datatype = 'Bin. base64 ';
// Open the Stream object and read the source file
Ado_stream.Type = 1; // 1 = adTypeBinary
Ado_stream.Open ();
Ado_stream.LoadFromFile ('C: \ tmp \ myfile.doc ');
// Save the file content to the XML node
L_node1.nodeTypedValue = ado_stream.Read (-1); //-1 = adReadAll
Ado_stream.Close ();
Xml_dom.documentElement.appendChild (l_node1 );

// Multiple binary nodes can be created to upload multiple files at a time

// Send the XML document to the Web server
Var xmlhttp = new ActiveXObject ('Microsoft. xmlhttp ');
Xmlhttp. open ('post', './file_recieve.asp', false );
Xmlhttp. send (xml_dom );
// Display the information returned by the server
Div_message.innerHTML = xmlhttp. ResponseText;
}
</SCRIPT>


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.