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

Source: Internet
Author: User
Tags count file upload implement domain
Upload | No Component Day Seventh: implement additional functionality

Today, we are going to implement the methods and attributes proposed yesterday to refine our file upload class. A performance problem that has not been paid much attention to before, and this time to be completely resolved:
1. All variables are declared first and then used;
2. Set the Teminate method of the class;
3. Simplify the wording of some places and pay attention to details.
Our principle is to achieve first, after optimization. Of course, such things as variable declarations, if the program is large, it is best to write the program once. If it's finished, you can add Option Explicit (force variable declaration) at the beginning of the page, and then test all the methods and properties until there is no error.

In addition, the exception code we also tidy up:
Code class name Type description
==============================================================================
One formelement indexoutofbound form element subset index bounds
FormElement illegalargument Illegal FORM element subset index
Uploadrequest indexoutofbound text element index out of bounds
Uploadrequest illegalargument Illegal text element index
Uploadrequest indexoutofbound file Element index out of bounds
Uploadrequest nullref file Element index does not exist
Uploadrequest illegalargument Illegal FORM element index
Uploadrequest toolargefile file%fldname size is too large
Uploadrequest toolargefiles file Total size is too large
Uploadrequest invalidfiletype file%fldname type error

Well, here's the whole realization:
1. Com.2yup.util.uploadrequest.class
<%
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' No copyright, welcome to copy or for commercial use.
' If you want to reprint, can indicate the best source, we will be very grateful to your support; if inconvenient, even if, hehe.
' Thank you often to 2yup of netizens (many names, not write, hehe) long-term enthusiastic support,
' You are my enduring power.
'
' Detailed information about this component, and the whole process of programming, can be
' Http://www.2yup.com/asp
' Document Center to see what's going on. Have any questions, welcome to our forum discussion, or send me an email:
' Miles2yup@hotmail.com
'----Miles [Yup Studio] ^ ^
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

'=========================================================================
"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

' Set nothing is fired. Clean up resources
Private Sub Class_Terminate ()
Set M_dicitems = Nothing
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 ()
Dim Keys
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)
Dim Items, I
If isnumeric (Index) Then ' is number, legal!
If Index > M_dicitems.count-1 Then
Err.Raise, "Indexoutofbound", "TABLE element subset index out of bounds"
End If
Items = M_dicitems.items
Item = Items (index)
ElseIf index = "Then ' does not give a value?" Then go back to all! Comma separated
Items = M_dicitems.items
For i = 0 to M_dicitems.count-1
If i = 0 Then
Item = Items (0)
Else
Item = Item & "," & Items (i)
End If
Next
Else ' Give a thing that is not a number? Error!
Err.Raise, "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_brawdata
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

' This property is embarrassing. The--stream object write method requires a data type that is
"A Variant that is contains an array of the bytes to be written."
' But I can't get this data type from a binary string! It's really strange. So, I'm going to
' Use raw data m_brawdata that meets the requirements. However, the class functionality of the VBS is woefully poor and can neither deliver
' Reference to the current object to return a visit to Uploadrequest's m_brawdata can not be used inner class's side
' The law is organized. To keep the method simple, add this write-only rawdata attribute.
' This place is worth improving.
Public Property Let RawData (data)
M_brawdata = Data
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 Pro



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.