ASP no component upload

zhaozj2021-02-16  53

Note: Part of the collected part from the Internet and written some. The main upgrade is a class package for Form's binary data, which can be easily obtained from the information of the elements within the Form.

FORM binary data format:

Split marker data 0x0d

0A

Element Description Information 0x0D

0A

0D

0A

Element content data 0x0d

0A

Split marker data 0x0d

0A

Element Description Information 0x0D

0A

0D

0A

Element content data 0x0D

0A

......

Split marker data 0x0d

0A

1. UPLOAD.HTM

file upload </ title> </ head></p> <p><body></p> <p><form encType = "multipart / form-data" Action = "Upload.asp" Method = "POST"></p> <p><Input Name = "Text0" Type = Text Value = "Text Box"> <br></p> <p><input name = "file1" type = file accept = "image / *"> <br></p> <p><input name = "file2" type = file accept = "image / *"> <br></p> <p><Input Type = Submit Value = "Upload"></p> <p></ form></p> <p></ body></p> <p></ html></p> <p>2. Upload.asp</p> <p><! - # include file = "Upload.inc" -></p> <p><%</p> <p>'by Sam 2004, 6</p> <p>'######################################################## ####</p> <p>Response.expires = 0</p> <p>If Request.servervariables ("Request_Method") = "post" then</p> <p>Response.clear ()</p> <p>Response.buffer = TRUE</p> <p>Set uform = New UploadForm</p> <p>uform.find_element "text0"</p> <p>Data = MIDB (uform.formdata, uform.datast, uform.datalen)</p> <p>Response.binaryWrite Data</p> <p>SDATA = BinaryTostring (DATA)</p> <p>Response.write SDATA</p> <p>Response.binaryWrite StringTobinary (SDATA)</p> <p>uform.find_element "file1"</p> <p>Savefile server.mappath ("/ recv1.dat"), uform.formdata, uform.datastart, uform.Datalen</p> <p>uform.find_element "file2"</p> <p>Savefile server.mappath ("/ recv2.dat"), uform.formdata, uform.datastart, uform.datalen</p> <p>SET uform = Nothing</p> <p>END IF</p> <p>%></p> <p>3. UPLOAD.INC <%</p> <p>'by Sam 2004, 6</p> <p>'#########################################################</p> <p>Function Savefile (FileName, Formdata, Start, Len)</p> <p>SET STRM1 = Server.createObject ("adodb.stream")</p> <p>SET STRM2 = Server.createObject ("AdoDb.Stream")</p> <p>Strm1.open</p> <p>Strm1.type = 1 'binary</p> <p>Strm2.open</p> <p>Strm2.type = 1 'binary</p> <p>Strm1.write Formdata</p> <p>'strm1.savetofile server.mappath ("/ 1.RAW"), 2</p> <p>Strm1.position = start - 1</p> <p>Strm1.couthto strm2, len</p> <p>'strm2.savetofile server.mappath ("/ 1.gif"), 2</p> <p>Strm2.savetofile filename, 2</p> <p>SET STRM1 = Nothing</p> <p>SET STRM2 = Nothing</p> <p>END FUNCTION</p> <p>Function SimpleBinaryToString (binary)</p> <p>DIM I, S</p> <p>For i = 1 to lenb (binary)</p> <p>S = S & CHR (ASCB (MIDB (Binary, I, 1))))))</p> <p>NEXT</p> <p>SimpleBinaryToString = S</p> <p>END FUNCTION</p> <p>Function binarytostring (binary)</p> <p>DIM CL1, CL2, CL3, PL1, PL2, PL3</p> <p>Diml</p> <p>CL1 = 1</p> <p>CL2 = 1</p> <p>CL3 = 1</p> <p>l = lenb (binary)</p> <p>Do While CL1 <= L</p> <p>PL3 = PL3 & CHR (ASCB (MIDB (Binary, CL1, 1))))</p> <p>CL1 = CL1 1</p> <p>CL3 = CL3 1</p> <p>IF CL3> 300 THEN</p> <p>PL2 = PL2 & PL3</p> <p>PL3 = ""</p> <p>CL3 = 1</p> <p>CL2 = CL2 1</p> <p>IF CL2> 200 THEN</p> <p>PL1 = PL1 & PL2</p> <p>PL2 = ""</p> <p>CL2 = 1</p> <p>END IF</p> <p>END IF</p> <p>loop</p> <p>BinaryToString = PL1 & PL2 & PL3</p> <p>END FUNCTION</p> <p>Function StringTobinary (String)</p> <p>DIM I, B</p> <p>For i = 1 to len (string)</p> <p>B = B & ChRB (ASC (MID (String, I, 1))))</p> <p>NEXT</p> <p>StringTobinary = B</p> <p>END FUNCTION</p> <p>Class UploadForm</p> <p>Private sub coplass_initialize ()</p> <p>DataStart = 0</p> <p>Datalen = 0</p> <p>Formsize = Request.totalbytes</p> <p>Formdata = Request.binaryRead (Formsize)</p> <p>'response.write "<br> Myclass Start <br>"</p> <p>End Sub</p> <p>Private sub coplass_terminate ()</p> <p>'response.write "<br> Myclass over <br>" End Sub</p> <p>Public DataStart</p> <p>Public Datalen</p> <p>Public Formsize</p> <p>Public Formdata</p> <p>Public Sub Find_Element (Name)</p> <p>DataStart = 0</p> <p>Datalen = 0</p> <p>Bncrlf = chrb (13) & chrb (10)</p> <p>Strname = "name =" & chr (34) & name & chr (34)</p> <p>SPOS = 1</p> <p>EPOS = 1</p> <p>K = 0</p> <p>Do While (Spos <formsize)</p> <p>EPOS = INSTRB (SPOS, FORMDATA, BNCRLF)</p> <p>Divider = MIDB (Formdata, Spos, EPOS - SPOS)</p> <p>SDIVIDER = BinaryToString (Divider)</p> <p>'Response.write SDIVIDER & "<br>"</p> <p>'response.binarywrite divider & "<br>"</p> <p>SPOS = EPOS 2</p> <p>EPOS = INSTRB (Spos, Formdata, Bncrlf & Bncrlf)</p> <p>Header = MIDB (Formdata, SPOS, EPOS - SPOS)</p> <p>Sheader = binarytostring (header)</p> <p>'Response.write Sheader & "<br>"</p> <p>'response.binarywrite header & "<br>"</p> <p>Spos = EPOS 4</p> <p>EPOS = INSTRB (SPOS, FORMDATA, DIVIDER)</p> <p>IF INSTR (SHEADER, STRNAME> 0 THEN</p> <p>DataStart = SPOS 'base 1</p> <p>Datalen = EPOS - SPOS - 2</p> <p>'response.write "start =" & datastart & "<br>"</p> <p>'response.write "end =" & datalenten & "<br>"</p> <p>'Savefile Server.mappath ("/ Output.dat"), Formdata, Datastart, Datalen</p> <p>Exit do</p> <p>END IF</p> <p>Spos = EPOS</p> <p>K = K 1</p> <p>IF (k> 20) THEN</p> <p>Exit do</p> <p>END IF</p> <p>loop</p> <p>End Sub</p> <p>END CLASS</p> <p>%></p> <p>Sam SHA</p> <p>Sam_sha@sina.com.cn</p> <p>2004-6-7</p></div><div class="text-center mt-3 text-grey"> 转载请注明原文地址:https://www.9cbs.com/read-20720.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="20720" 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.041</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 = 'N4OgvbKzcRBHN3TavmYmTdOojEx_2Fg9mwxF5X5iXl_2FmpOo4C2xXCypLvXSCw7CCIx_2BblkRSnRHhE_2BTEFPA1Tdsg_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>