ASP file upload the third heavy: integrated category, multilingual universal, easy to use

Source: Internet
Author: User
Tags definition class definition file upload readable reference save file variable
Uploading this question is not a new problem, there are a lot of tutorials online, but most of the people to give the fish, and not to give people to fishing, after hard , thinking, debugging, finishing, I have basically made this problem from the principle of clear, now based on my own understanding, on the basis of the sample procedure, to explain, I hope to be able to some netizens (more than I:-)) help.

I ask you to correct the mistakes and the bad.

The use of Stream objects in the program refers to the "transformation HTTP Upload Program Version 2.0" in the code, here to the old farmer and Liang Tao without fear to express my heartfelt thanks and sincere respect.

First of all, for the next data analysis algorithm to manage the basis for the following is my excerpt from a small section of the page submitted to the binary data:
-----------------------------7d31ec15102d0
Content-disposition:form-data; Name= "Txttitle"

The idea of a full brain
-----------------------------7d31ec15102d0
Content-disposition:form-data; Name= "Filimage"; Filename= "F:\material\ wood grain Background \pic016.jpg"
Content-type:image/pjpeg

? Jfifc

!! E. '. Eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee?€ "
? !1aqa "Q2 nobody? #B绷R佯 $3br?
侼 s 歊 J 佦 =ǜ 珻,%?? Xm 銓 鼽 幮?? 驲 湕 胄 HSBC c?
儗 g? 咶? Ts? b 矠: U hide C
G l Yan H ' 啨 0p
G destroyers 41?9 ' $ feast 奆] 眬 stop? Swirl "? ?
-----------------------------7d31ec15102d0
Content-disposition:form-data; Name= "Btnupload"

Upload
-----------------------------7d31ec15102d0--

The content of the blue character we should be familiar with it, the middle of the garbled is the content of the file upload, in fact, we have to do is to do this pile of data analysis, pick out the useful data to save it OK. Analysis of data is to find some of the iconic content, such as carriage return line, "----------" symbol, with two pointers to determine two locations, and then extract data, my algorithm does not know good, my data structure is very bad, very sorry.

Here is a finished application in which the class definition can be used with another file, as long as the

<!--include file= "Ljupload.cls"-->

The command will be included in it.

Ljupload.asp:

<%@ Language=vbscript%>
<% Option Explicit%>

<script Language=vbscript runat=server>

Private Srmrequestdata ' ADODB.stream object, saving all data submitted from form

Private adTypeBinary ' ADODB.stream objects: returning binary data
Private adTypeText ' ADODB.stream objects: returning text data
Private adModeRead ' ADODB.stream objects: Object readable
Private adModeWrite ' ADODB.stream objects: Object writable
Private adModeReadWrite ' ADODB.stream objects: objects can read and write

Class Ljupload ' defines a category with a name of Ljupload.
  
Private Bytcrlf ' single byte carriage return line feed, total 2 bytes
Private bytsub ' single byte '-' symbol, total 8 bytes
Private bindata ' binary data variable, save a copy of the submitted data, then operate

Private Dicform ' Save information for form text field
Private Dicfile ' Save information for form file fields
Private StrName ' form enter the field name of the form
Private strvalue ' form input field value
Private objfile ' File information object, save file related information, specific reference to the definition of class Ljfile

Private PosB ' binary data read and write pointer, start pointer
Private PosE ' binary data read and write pointer, end pointer
Public Charset ' Language property settings
  
Private Sub Class_Initialize ' class initialization process
   
Bytcrlf = Getsbfromdb (vbCrLf)
Bytsub = Getsbfromdb ("--------")
Charset = "gb2312" Default language property set to Simplified Chinese: gb2312
   
adTypeBinary = 1 ' returns binary data
adTypeText = 2 ' Returns text data
adModeRead = 1 ' Object data readable
adModeWrite = 2 ' Object data writable
adModeReadWrite = 3 ' object data readable and writable
End Sub
  
Public Sub GetData ' class opening process, uploading files and analyzing data
   
Set srmrequestdata = Server. CreateObject ("ADODB.stream") ' establishes a ADODB.stream object
   
Srmrequestdata.type = adTypeBinary ' Specifies the return data type
Srmrequestdata.mode = adModeReadWrite ' Specifies open mode
Srmrequestdata.open ' Open Object
Srmrequestdata.write request. BinaryRead (Request. TotalBytes) ' Get all data submitted by Form
   
srmrequestdata.position = 0 ' read-write pointer reposition to object header, write data, pointer to end of object
Bindata = Srmrequestdata.read ' holds a copy of the submitted data in a variable and then operates
   
Set dicform = Server. CreateObject ("Scripting.Dictionary") ' is used to save text information
Set dicfile = Server. CreateObject ("Scripting.Dictionary") ' is used to save file information

PosB = INSTRB (bindata,bytsub) ' starts parsing the acquired binary data
PosB = INSTRB (POSB,BINDATA,BYTCRLF) + 2 ' +2 is the length of the Enter line feed character itself
PosB = INSTRB (Posb,bindata,getsbfromdb ("Name=" "")) + 6
Do Until PosB = 6 ' control conditions are set in a variety of ways, here for reference only
PosE = INSTRB (Posb,bindata,getsbfromdb ("" "))
StrName = Gettextfrombin (SRMREQUESTDATA,POSB,POSE-POSB)
   
PosB = PosE + 1 ' pointer moves to the rear of ' "
PosE = INSTRB (POSB,BINDATA,BYTCRLF)
    
If INSTRB (MidB (BINDATA,POSB,POSE-POSB), Getsbfromdb ("Filename=" ")) > 0 Then ' This is a file field
PosB = INSTRB (Posb,bindata,getsbfromdb ("Filename=" "")) + 10
PosE = INSTRB (Posb,bindata,getsbfromdb ("" "))
Set objfile = new Ljfile ' Creates a file information object
If POSE&GT;POSB Then
Objfile.filename = Getfilenamefrompath (Gettextfrombin (SRMREQUESTDATA,POSB,POSE-POSB)) ' Write file name
PosB = INSTRB (Posb,bindata,getsbfromdb ("Content-type:")) + 14
PosE = INSTRB (POSB,BINDATA,BYTCRLF)
O






Related Article

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.