XML technology upload file

xiaoxiao2021-04-09  453

SUMMARY This paper explains an example of using XML technology to upload files, using this method without all kinds of limits in the conventional method. This example tells how this new upload method is implemented using MSXML3.0 and ADO Stream objects. There are many advantages, for example, there is no need for dedicated upload components. Introduction To get the upload function in the HTML page, we can use the form:

> This scheme has many restrictions on the client and server. First, we must use the POST method because the GET method cannot handle such form data. Also, there is no way to trigger a POST action without using a form. After sending data to the form handler, the browser will load the handler as a new page, and then the user will see a page conversion process that does not expect. ENCTYPE Attribute Defines the MIME encoding method for the form. The encType property of the form of the upload file must use "Multipart / Form-Data". Set this property to "Multipart / Form-Data" created a POST buffer (composite structure) different from the traditional structure, the ASP's Request object cannot access such form content. So, we can use the Request.BinaryRead method to access these data, but you can't use the scripting language to complete all. Request.binaryRead method Returns a VTARRAY type data (only a Variant type array of unmanned byte characters). But the scripting language can only handle Variant data. To solve this problem, you can only use a dedicated ASP upload component, or the ISAPI extension, such as cpshost.dll. This is a design restriction. The new uploading scheme needs to be operated as follows. Client: Create an XML document using MSXML 3.0 Creating an XML node for binary content Using ADO Stream Object Add Uploaded file data into the Node Use XMLHTTP object to send this XML document to the web server server: read from the Request object The XML document reads the data in the binary node and stores the file on the server. Of course, we can also store them into the BLOB field of the database. Before explaining this code, we can think about this program. Think about XML XML format supports many data types, such as Numeric, Float, Character, and more. Many authors define XML as ASCII formats, but we cannot ignore, XML technology can also use the "bin.base64" data type to describe binary information. This feature is fully supported in the MS XML3.0 parser, but some special settings are required. This object provides some properties that can be fully controlled to binary data: OBJ_NODE.DATATYPE - The readable and writable attribute defines the data type of a particular node. The MSXML parser supports more data types (see msdn: http://msdn.microsoft.com/library/psdk/xmlsdk/xmls3z1v.htm) For binary data, we can use the "bin.base64" type.

OBJ_Node.NodeTypedValue - The readable write property contains data in specified nodes represented by the setting type. We can create an XML document containing multiple bin.base64 type nodes, which contains uploaded files. This feature can use a POST upload multiple files at a time. We can send an XML document to the web server using the XMLHttpRequest object and the POST method. This object provides client protocol support for HTTP servers, allowing MS XMLDOM objects to be sent and accepted on a web server. XMLHttpRequest is a COM object built into Internet Explorer 5 (do not need to be customized), and no conversion page is required after sending. Thoughts on the ADO Stream object We can create an XML document containing one or more binary nodes on the client. We must also fill the file content into the node. But unfortunately, the scripting language cannot access the local file system, and the scripting.FileSystem object (the built-in object of the Win32 system) is not available so far. This is a design restriction. So we need to find a COM object that can provide access to local binary files. ADO Stream objects (components in MDAC 2.5) provide means for reading, writing, and managing binary flow data. The content of the byte stream can be text, or binary data, and there is no limit on capacity. In ADO 2.5, Microsoft's introduction to the Stream object is not any layer of the ADO object structure, so we can use this object without bundling. This article uses the Stream object to access the file content, and then store the content into the XML node. The following sample code completes the file upload action using the Stream and MSXML objects.

file send </ title> </ head> <body> <input id = btn_send name = 'btn_send' type = button value = 'file send'> <div id = div_message> Ready < / Div> </ body> </ html> <script language = javascript> // upload function function function btn_send.onClick () {// Create 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 '?> <Root />'); // Specify data Type XML_DOM.Documentelement.setttribute ('XMLns: DT', 'URN: Schemas-Microsoft-COM: DATATYPES'); // Create a new node, set it as binary data node var l_node1 = XML_DOM.CREATEEEEMENT ('file1') l_node1.datatype = 'bin.base64'; // Open the stream object, read source file ado_stream.type = 1; // 1 = adtypebinary ado_stream.open (); ado_stream.loadFromFile ('c: // tmp // myfile .doc '); // store the file into the XML node l_node1.nodetyped (-1); // -1 = adreadallado_stream.close (); xml_dom.documentelement.Appendchild (l_node1); // can be created Multiple binary nodes, upload multiple files at a time // send the XML document to the web server var xmlhttp = new activiXObject ('microsoft.xmlhttp'); XMLHttp.Open ('POST', '. /FALSE) The information Div_MLHTTTTTML = xmlhttp.innerHTML = XMLHTTP.RESPONSETEXT;} </ script> Server side code uses the same object to provide server-side upload processing functions . <% @ Language = VBScript%> <% OPTION ExplicitResponse.expires = 0 'Defines variables and objects.</p></div><div class="text-center mt-3 text-grey"> 转载请注明原文地址:https://www.9cbs.com/read-133107.html</div><div class="plugin d-flex justify-content-center mt-3"></div><hr><div class="row"><div class="col-lg-12 text-muted mt-2"><i class="icon-tags mr-2"></i><span class="badge border border-secondary mr-2"><h2 class="h6 mb-0 small"><a class="text-secondary" href="tag-2.html">9cbs</a></h2></span></div></div></div></div><div class="card card-postlist border-white shadow"><div class="card-body"><div class="card-title"><div class="d-flex justify-content-between"><div><b>New Post</b>(<span class="posts">0</span>) </div><div></div></div></div><ul class="postlist list-unstyled"> </ul></div></div><div class="d-none threadlist"><input type="checkbox" name="modtid" value="133107" checked /></div></div></div></div></div><footer class="text-muted small bg-dark py-4 mt-3" id="footer"><div class="container"><div class="row"><div class="col">CopyRight © 2020 All Rights Reserved </div><div class="col text-right">Processed: <b>0.039</b>, SQL: <b>9</b></div></div></div></footer><script src="./lang/en-us/lang.js?2.2.0"></script><script src="view/js/jquery.min.js?2.2.0"></script><script src="view/js/popper.min.js?2.2.0"></script><script src="view/js/bootstrap.min.js?2.2.0"></script><script src="view/js/xiuno.js?2.2.0"></script><script src="view/js/bootstrap-plugin.js?2.2.0"></script><script src="view/js/async.min.js?2.2.0"></script><script src="view/js/form.js?2.2.0"></script><script> var debug = DEBUG = 0; var url_rewrite_on = 1; var url_path = './'; var forumarr = {"1":"Tech"}; var fid = 1; var uid = 0; var gid = 0; xn.options.water_image_url = 'view/img/water-small.png'; </script><script src="view/js/wellcms.js?2.2.0"></script><a class="scroll-to-top rounded" href="javascript:void(0);"><i class="icon-angle-up"></i></a><a class="scroll-to-bottom rounded" href="javascript:void(0);" style="display: inline;"><i class="icon-angle-down"></i></a></body></html><script> var forum_url = 'list-1.html'; var safe_token = 'eMa05HOBAFwCgT5ZD6GaK7n4NQLf9GSKYkscJVm9drZhXRd54azbKMBcjiCUVGz5i1NtHYZU9WZCbLmuORVlCg_3D_3D'; var body = $('body'); body.on('submit', '#form', function() { var jthis = $(this); var jsubmit = jthis.find('#submit'); jthis.reset(); jsubmit.button('loading'); var postdata = jthis.serializeObject(); $.xpost(jthis.attr('action'), postdata, function(code, message) { if(code == 0) { location.reload(); } else { $.alert(message); jsubmit.button('reset'); } }); return false; }); function resize_image() { var jmessagelist = $('div.message'); var first_width = jmessagelist.width(); jmessagelist.each(function() { var jdiv = $(this); var maxwidth = jdiv.attr('isfirst') ? first_width : jdiv.width(); var jmessage_width = Math.min(jdiv.width(), maxwidth); jdiv.find('img, embed, iframe, video').each(function() { var jimg = $(this); var img_width = this.org_width; var img_height = this.org_height; if(!img_width) { var img_width = jimg.attr('width'); var img_height = jimg.attr('height'); this.org_width = img_width; this.org_height = img_height; } if(img_width > jmessage_width) { if(this.tagName == 'IMG') { jimg.width(jmessage_width); jimg.css('height', 'auto'); jimg.css('cursor', 'pointer'); jimg.on('click', function() { }); } else { jimg.width(jmessage_width); var height = (img_height / img_width) * jimg.width(); jimg.height(height); } } }); }); } function resize_table() { $('div.message').each(function() { var jdiv = $(this); jdiv.find('table').addClass('table').wrap('<div class="table-responsive"></div>'); }); } $(function() { resize_image(); resize_table(); $(window).on('resize', resize_image); }); var jmessage = $('#message'); jmessage.on('focus', function() {if(jmessage.t) { clearTimeout(jmessage.t); jmessage.t = null; } jmessage.css('height', '6rem'); }); jmessage.on('blur', function() {jmessage.t = setTimeout(function() { jmessage.css('height', '2.5rem');}, 1000); }); $('#nav li[data-active="fid-1"]').addClass('active'); </script>