1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
| <%
Server.ScriptTimeout = 60
Const ForWriting = 2
Const TristateTrue = -1
CrLf = Chr(13) & Chr(10)
Function GetFieldName(infoStr)
sPos = InStr(infoStr, "name=")
EndPos = InStr(sPos + 6, infoStr, Chr(34) & ";")
If EndPos = 0 Then
EndPos = inStr(sPos + 6, infoStr, Chr(34))
End If
GetFieldName = Mid(infoStr, sPos + 6, endPos - _
(sPos + 6))
End Function
Function GetFileName(infoStr)
sPos = InStr(infoStr, "filename=")
EndPos = InStr(infoStr, Chr(34) & CrLf)
GetFileName = Mid(infoStr, sPos + 10, EndPos - _
(sPos + 10))
End Function
Function GetFileType(infoStr)
sPos = InStr(infoStr, "Content-Type: ")
GetFileType = Mid(infoStr, sPos + 14)
End Function
PostData = ""
Dim biData
biData = Request.BinaryRead(Request.TotalBytes)
For nIndex = 1 to LenB(biData)
PostData = PostData & Chr(AscB(MidB(biData,nIndex,1)))
Next
ContentType = Request.ServerVariables( _
"HTTP_CONTENT_TYPE")
ctArray = Split(ContentType, ";")
If Trim(ctArray(0)) = "multipart/form-data" Then
ErrMsg = ""
bArray = Split(Trim(ctArray(1)), "=")
Boundary = Trim(bArray(1))
FormData = Split(PostData, Boundary)
Dim myRequest, myRequestFiles(9, 3)
Set myRequest = CreateObject("Scripting.Dictionary")
FileCount = 0
For x = 0 to UBound(FormData)
InfoEnd = InStr(FormData(x), CrLf & CrLf)
If InfoEnd > 0 Then
varInfo = Mid(FormData(x), 3, InfoEnd - 3)
varValue = Mid(FormData(x), InfoEnd + 4, _
Len(FormData(x)) - InfoEnd - 7)
If (InStr(varInfo, "filename=") > 0) Then
myRequestFiles(FileCount, 0) = GetFieldName( _
varInfo)
myRequestFiles(FileCount, 1) = varValue
myRequestFiles(FileCount, 2) = GetFileName( _
varInfo)
myRequestFiles(FileCount, 3) = GetFileType( _
varInfo)
FileCount = FileCount + 1
Else
myRequest.add GetFieldName(varInfo), varValue
End If
End If
Next
Else
ErrMsg = "Wrong encoding type!"
End If
Set lf = server.createObject("Scripting.FileSystemObject")
If myRequest("filename") = "original" Then
BrowserType = UCase(Request.ServerVariables( _
"HTTP_USER_AGENT"))
If (InStr(BrowserType, "WIN") > 0) Then
sPos = InStrRev(myRequestFiles(0, 2), "\")
fName = Mid(myRequestFiles(0, 2), sPos + 1)
End If
If (InStr(BrowserType, "MAC") > 0) Then
fName = myRequestFiles(0, 2)
End If
FilePath = "./Pictures/" & fName
End If
SavePath = Server.MapPath(FilePath)
Set SaveFile = lf.CreateTextFile(SavePath, True)
SaveFile.Write(myRequestFiles(0, 1))
SaveFile.Close
%>
<html>
<body>
<% If ErrMsg = "" Then %>
<% response.write "[img]Pictures/"[/img]"%>
<br>
Bedankt voor het plaatje! Het was erg lekker!
<% Else %>
<%= ErrMsg %>
<% End If %>
</body>
</html> |