ASP no component upload • From principle analysis to practice (middle)

Source: Internet
Author: User
Tags contains count file size requires variable domain domain name client
Upload | No component fifth day: Get file unit

The part we're going to do today is more interesting--getting the file content. In fact, look at the data we have to deal with, and then look at the processing of the former astronomical unit, I believe we will have a good idea.

For a clear distinction between files and text units, this time, we use Ourrequest.file (index) to correspond to the Ourrequest.form (index) of the text unit. Of course, because for the file, we need to get the information is different from the text, so this time, it will not be formelement, but a new object fileelement.

File units and text units in the original data, the difference is very little poor:
1. The first line more than a filename= "xxx" module;
2. There is a second line to indicate ContentType.

The target information of interest is different, so the object fileelement and FormElement have some different points:
1. The Count property is not required (no checkbox condition exists);
2. Item (index) not required (IBID., no checkbox);
3. Requires a contenttype attribute;
4. Requires a filepath attribute;
5. Requires a filename attribute;
6. Requires a size attribute;
7. Because the need is binary, so, it is not necessary to binary => string conversion;
8. Because it needs to be binary, it is more appropriate to change the property value to data

In addition, Uploadrequest should add the files attribute, the Form (index) method, and the M_dicfiles member accordingly. Now we're going to expand him:
A. Uploadrequest (designed above, here is expansion)
This class is corresponding to the request object
Property:
RawData get raw data, easy to check [Read Only]
Forms gets a counter with the Count property,
You can use OutRequest.Forms.Count to get the number of text form fields [read-only]
Files get a counter with the Count property,
You can use OutRequest.Files.Count to get the number of file form fields [read-only]
Form (index) can be used to retrieve text form fields using numbers or text, similar to Request.Form.
He returned an object of formelement type
File (index) can retrieve a document form field with numbers or text, and he returns an object of Fileelement type
B. Fileelement
It can be seen as the embodiment of a single file domain. Through this class, you can get detailed file information, such as name,data,path,filename,contenttype,size and so on.
Property:
The name of a name file field. It's xxx in <input type=file name=xxx>.
The contents of the Data file field. Binary string
ContentType of ContentType file domain
FilePath file domain contains files in full path on client
filename of filename file field contains file
Sizes of files contained in the Size file field

Here is the implementation. Or to save into a doupload.asp:
<%
'=========================================================================
"This is the class that stores the text field information. A text field for each name that corresponds to one of these classes.
'=========================================================================
Class FormElement

' M_, representing the class member variable.
Private M_dicitems

Private Sub Class_Initialize ()
Set M_dicitems = Server.CreateObject ("Scripting.Dictionary")
End Sub

' Count is a read-only property of our class
Public Property Get Count ()
Count = M_dicitems.count
End Property

' Value is a default property. The goal is to get the value
Public Default Property Get Value ()
Value = Item ("")
End Property

' Name is the name of the text field. is xxx in <input name=xxx>.
Public Property Get Name ()
Keys = M_dicitems.keys
Name = Keys (0)
Name = Left (Name,instrrev (name, "_")-1)
End Property

The ' Item property is used to get a value for the duplicate table fields (such as a checkbox)
Public Property Get Item (Index)
If isnumeric (Index) Then ' is number, legal!
If Index > M_dicitems.count-1 Then
Err.Raise 1, "Indexoutofbound", "TABLE element subset index out of bounds"
End If
ITMS = M_dicitems.items
Item = ITMS (index)
ElseIf index = "Then ' does not give a value?" Then go back to all! Comma separated
ITMS = M_dicitems.items
For i = 0 to M_dicitems.count-1
If i = 0 Then
Item = ITMS (0)
Else
Item = Item & "," & Itms (i)
End If
Next
Else ' Give a thing that is not a number? Error!
Err.Raise 2, "illegalargument", "illegal form element subset index"
End If
End Property

Public Sub ADD (key, item)
M_dicitems.add Key, item
End Sub

End Class

'=========================================================================
"This is the class that stores the file domain information. Each name of the file, corresponding to one such class.
'=========================================================================
Class fileelement

' M_, representing the class member variable.
Private M_strname
Private M_bdata
Private M_strcontenttype
Private M_strfilepath
Private M_strfilename
Private m_lsize

' Data is a default property. The goal is to get the value
Public Default Property Get Data ()
Data = M_bdata
End Property

' Name is to get file domain name, is <input type=file name=xxx> xxx
Public Property Get Name ()
Name = M_strname
End Property

' ContentType is getting file contenttype
Public Property Get ContentType ()
ContentType = M_strcontenttype
End Property

' FilePath is the path to getting the file on the client
Public Property Get FilePath ()
FilePath = M_strfilepath
End Property

' FilePath is the path to getting the file on the client
Public Property Get FileName ()
FileName = M_strfilename
End Property

' Size is getting file size
Public Property Get Size ()
Size = M_lsize
End Property

Public Sub ADD (name, data, contenttype, PATH)
M_strname = Name
M_bdat



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.