Solution for the component-less upload class of daoxiang old farmer, when the file name contains Chinese single double quotation marks, the correct file name cannot be obtained.

Source: Internet
Author: User

Today, we have completed the modification to the latest version of the component-less upload class V2.1.

Solved the problem that the correct file name cannot be obtained when the file name contains Chinese single double quotation marks during file upload.

I have referred to the upload without Fear class. I would like to thank the two teachers, daoxiang Lao Nong and Liang wushi, for providing their source code for free.

The modified code is attached below:

 

<SCRIPT runat = server Language = VBScript> dim data_5xsoftclass upload_5xsoft dim objform, objfile, versionpublic function form (strform) strform = lcase (strform) if not objform. exists (strform) then form = "" else form = objform (strform) end if end functionpublic function file (strfile) strfile = lcase (strfile) if not objfile. exists (strfile) then set file = new fileinfo else set file = objfile (strfile) end if end functionprivate sub class_initialize dim requestdata, sstart, bcrlf, SINFO, iinfostart, iinfoend, tstream, istart, thefile dim ifilesize, sfilepath, sfiletype, sformvalue, sfilename dim ifindstart, ifindend dim iformstart, iformend, sformname version = "Environmental HTTP upload program version 2.1" set objform = server. createobject ("scripting. dictionary ") set objfile = server. createobject ("scripting. dictionary ") if request. totalbytes <1 then exit sub set tstream = server. createobject ("ADODB. stream ") set data_5xsoft = server. createobject ("ADODB. stream ") data_5xsoft.type = 1 data_5xsoft.mode = 3 data_5xsoft.open data_5xsoft.write request. binaryread (request. totalbytes) data_5xsoft.position = 0 requestdata = data_5xsoft.read iformstart = 1 iformend = lenb (requestdata) bcrlf = chrb (13) & chrb (10) sstart = midb (requestdata, 1, instrb (iformstart, requestdata, bcrlf)-1) istart = lenb (sstart) iformstart = iformstart + istart + 1 while (iformstart + 10) <iformend iinfoend = instrb (iformstart, requestdata, bcrlf & bcrlf) + 3tstream. type = 1tstream. mode = 3tstream. opendata_5xsoft.position = iformstartdata_5xsoft.copyto tstream, iInfoEnd-iFormStarttStream.Position = 0tstream. type = 2tstream. charset = "gb2312" SINFO = tstream. readtexttstream. close 'get form project name iformstart = required B (iinfoend, requestdata, sstart) ifindstart = instr (22, SINFO, "name =", 1) + 6 ifindend = instr (ifindstart, SINFO, ", 1) sformname = lcase (mid (SINFO, ifindstart, ifindend-ifindstart )) 'If the file is if instr (45, SINFO, "filename =", 1)> 0 thenset thefile = new fileinfo', get the file name ifindstart = instr (ifindend, SINFO, "filename =", 1) + 10 ifindend = instr (ifindstart, SINFO, "" & vbcrlf, 1) sfilename = mid (SINFO, ifindstart, ifindend-ifindstart) thefile. filename = getfilename (sfilename) thefile. filepath = getfilepath (sfilename) thefile. fileext = getfileext (sfilename) 'get the file type ifindstart = instr (ifindend, SINFO, "Content-Type:", 1) + 14 ifindend = instr (ifindstart, SINFO, vbcr) thefile. filetype = mid (SINFO, ifindstart, ifindend-ifindstart) thefile. filestart = iinfoendthefile. filesize = iformstart-iinfoend-3thefile. formname = sformnameif not objfile. exists (sformname) Then objfile. add sformname, thefileend ifelse 'if it is a Form Project tstream. type = 1tstream. mode = 3tstream. opendata_5xsoft.position = iinfoend data_5xsoft.copyto tstream, iFormStart-iInfoEnd-3tStream.Position = 0tstream. type = 2tstream. charset = "gb2312" sformvalue = tstream. readtext tstream. closeif objform. exists (sformname) Then objform (sformname) = objform (sformname) & "," & sformvalue else objform. add sformname, sformvalueend ifend ififormstart = iformstart + istart + 1 Wend requestdata = "" set tstream = nothingend subprivate sub class_terminate if request. totalbytes> 0 thenobjform. removeallobjfile. removeallset objform = nothingset objfile = jsondata_5xsoft = nothing end ifend sub private function getfilepath (fullpath) If fullpath <> "" Then getfilepath = left (fullpath, limit Rev (fullpath, "/") else getfilepath = "" end if end function private function getfileext (fullpath) If fullpath <> "" Then getfileext = mid (fullpath, limit Rev (fullpath ,". ") + 1) else getfileext =" "end if end function private function getfilename (fullpath) If fullpath <>" "Then getfilename = mid (fullpath, limit Rev (fullpath, "/") + 1) else getfilename = "" end if end functionend classclass fileinfo dim formname, filename, filepath, filesize, fileext, filetype, filestart private sub class_initialize filename = "" filepath = "" filesize = 0 filestart = 0 formname = "" filetype = "" fileext = "" End sub public function saveas (fullpath) dim DR, errorchar, I saveas = true if trim (fullpath) = "" Or filestart = 0 or filename = "" Or right (fullpath, 1) = "/" then exit function set DR = Createobject ("ADODB. stream ") DR. mode = 3 DR. type = 1 dr. open data_5xsoft.position = filestart data_5xsoft.copyto DR, filesize dr. savetofile fullpath, 2 dr. close set DR = nothing saveas = false end function end class </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.