Inserting Form content into the Database with ASP.
<%
'--loader.asp--
'--Version 1.5.2
'--Last updated 12/5/2002
'
' Faisal Khan
' Faisal@stardeveloper.com
' Www.stardeveloper.com
' Class for handling binary uploads
Class Loader
Private Dict
Private Sub Class_Initialize
Set dict = Server.CreateObject ("Scripting.Dictionary")
End Sub
Private Sub Class_Terminate
If IsObject (intdict) Then
Intdict.removeall
Set intdict = Nothing
End If
If IsObject (dict) Then
Dict. RemoveAll
Set dict = Nothing
End If
End Sub
Public Property Get Count
Count = Dict. Count
End Property
Public Sub Initialize
If request.totalbytes > 0 Then
Dim Bindata
Bindata = Request.BinaryRead (request.totalbytes)
GetData Bindata
End If
End Sub
Public Function Getfiledata (name)
If Dict. Exists (name) Then
Getfiledata = dict (name). Item ("Value")
Else
Getfiledata = ""
End If
End Function
Public Function GetValue (name)
Dim GV
If Dict. Exists (name) Then
GV = CSTR (dict (name). Item ("Value"))
GV = Left (Gv,len (GV)-2)
GetValue = GV
Else
GetValue = ""
End If
End Function
Public Function savetofile (name, path)
If Dict. Exists (name) Then
Dim Temp
temp = dict (name). Item ("Value")
Dim FSO
Set FSO = Server.CreateObject ("Scripting.FileSystemObject")
Dim file
Set file = fso. CreateTextFile (PATH)
For tpoint = 1 to LenB (temp)
File. Write Chr (AscB (MidB (temp,tpoint,1))
Next
File. Close
SaveToFile = True
Else
SaveToFile = False
End If
End Function
Public Function GetFileName (name)
If Dict. Exists (name) Then
Dim Temp, Temppos
temp = dict (name). Item ("FileName")
Temppos = 1 + instrrev (temp, "\")
GetFileName = Mid (temp, Temppos)
Else
GetFileName = ""
End If
End Function
Public Function GetFilePath (name)
If Dict. Exists (name) Then
Dim Temp, Temppos
temp = dict (name). Item ("FileName")
Temppos = InStrRev (temp, "\")
GetFilePath = Mid (temp, 1, Temppos)
Else
GetFilePath = ""
End If
End Function
Public Function Getfilepathcomplete (name)
If Dict. Exists (name) Then
Getfilepathcomplete = dict (name). Item ("FileName")
Else
Getfilepathcomplete = ""
End If
End Function
Public Function GetFileSize (name)
If Dict. Exists (name) Then
GetFileSize = LenB (dict (name). Item ("Value"))
Else
GetFileSize = 0
End If
End Function
Public Function getfilesizetranslated (name)
If Dict. Exists (name) Then
temp = LenB (dict (name). Item ("Value"))
If Temp <= 1024 Then
getfilesizetranslated = temp & "bytes"
Else
temp = FormatNumber ((temp/1024), 2)
getfilesizetranslated = temp & "Kilobytes"
End If
Else
getfilesizetranslated = ""
End If
End Function
Public Function getContentType (name)
If Dict. Exists (name) Then
getContentType = dict (name). Item ("ContentType")
Else
getContentType = ""
End If
End Function
Private Sub GetData (rawdata)
Dim Separator
Separator = MidB (rawdata, 1, InstrB (1, RawData, ChrB (13))-1)
Dim Lenseparator
Lenseparator = LenB (separator)
Dim Currentpos
Currentpos = 1
Dim Instrbyte
Instrbyte = 1
Dim value, Mvalue
Dim Tempvalue
Tempvalue = ""
While Instrbyte > 0
Instrbyte = InStrB (Currentpos, rawdata, separator)
Mvalue = Instrbyte-currentpos
If mvalue > 1 Then
Value = MidB (RawData, Currentpos, Mvalue)
Dim Begpos, Endpos, Midvalue, Nvalue
Dim intdict
Set intdict = Server.CreateObject ("Scripting.Dictionary")
Begpos = 1 + InStrB (1, Value, ChrB (34))
Endpos = InStrB (Begpos + 1, value, ChrB (34))
Nvalue = Endpos
Dim Namen
Namen = MidB (value, Begpos, Endpos-begpos)
Dim Namevalue, IsValid
IsValid = True
If InStrB (1, Value, Stringtobyte ("Content-type")) > 1 Then
Begpos = 1 + InStrB (endpos + 1, value, ChrB (34))
Endpos = InStrB (Begpos + 1, value, ChrB (34))
If endpos = 0 Then
Endpos = Begpos + 1
IsValid = False
End If
Midvalue = MidB (value, Begpos, Endpos-begpos)
Intdict.add "FileName", Trim (bytetostring (midvalue))
Begpos = + InStrB (endpos + 1, value, Stringtobyte ("Content-type:"))
Endpos = InStrB (Begpos, Value, ChrB (13))
Midvalue = MidB (value, Begpos, Endpos-begpos)
Intdict.add "ContentType", Trim (bytetostring (midvalue))
Begpos = Endpos + 4
Endpos = LenB (value)
Namevalue = MidB (Value, Begpos, ((Endpos-begpos)-1))
Else
Namevalue = Trim (bytetostring (MidB (value, Nvalue + 5))
End If
If isValid = True Then
Intdict.add "Value", Namevalue
Intdict.add "Name", Namen
Dict. ADD bytetostring (Namen), intdict
End If
End If
Currentpos = Lenseparator + instrbyte
Wend
End Sub
End Class
Private Function stringtobyte (TOCONV)
Dim Tempchar
For i = 1 to Len (TOCONV)
Tempchar = Mid (Toconv, I, 1)
Stringtobyte = stringtobyte & ChrB (AscB (Tempchar))
Next
End Function
Private Function bytetostring (TOCONV)
For i = 1 to LenB (TOCONV)
bytetostring = bytetostring & Chr (AscB (MidB (toconv,i,1))
Next
End Function
%>