file:upload.asp
<%
author philippe collignon
email phcollignon@email.com
sub builduploadrequest(requestbin)
get the boundary
posbeg = 1
posend = instrb(posbeg,requestbin,getbytestring(chr(13)))
boundary = midb(requestbin,posbeg,posend-posbeg)
boundarypos = instrb(1,requestbin,boundary)
get all data inside the boundaries
do until (boundarypos=instrb(requestbin,boundary & getbytestring("–")))
members variable of objects are put in a dictionary object
dim uploadcontrol
set uploadcontrol = createobject("scripting.dictionary")
get an object name
pos = instrb(boundarypos,requestbin,getbytestring("content-disposition"))
pos = instrb(pos,requestbin,getbytestring("name="))
posbeg = pos+6
posend = instrb(posbeg,requestbin,getbytestring(chr(34)))
name = getstring(midb(requestbin,posbeg,posend-posbeg))
posfile = instrb(boundarypos,requestbin,getbytestring("filename="))
posbound = instrb(posend,requestbin,boundary)
test if object is of file type
if posfile<>0 and (posfile<posbound) then
get filename, content-type and content of file
posbeg = posfile + 10
posend = instrb(posbeg,requestbin,getbytestring(chr(34)))
filename = getstring(midb(requestbin,posbeg,posend-posbeg))
add filename to dictionary object
uploadcontrol.add "filename", filename
pos = instrb(posend,requestbin,getbytestring("content-type:"))
posbeg = pos+14
posend = instrb(posbeg,requestbin,getbytestring(chr(13)))
add content-type to dictionary object
contenttype = getstring(midb(requestbin,posbeg,posend-posbeg))
uploadcontrol.add "contenttype",contenttype
get content of object
posbeg = posend+4
posend = instrb(posbeg,requestbin,boundary)-2
value = midb(requestbin,posbeg,posend-posbeg)
else
get content of object
pos = instrb(pos,requestbin,getbytestring(chr(13)))
posbeg = pos+4
posend = instrb(posbeg,requestbin,boundary)-2
value = getstring(midb(requestbin,posbeg,posend-posbeg))
end if
add content to dictionary object
uploadcontrol.add "value" , value
add dictionary object to main dictionary
uploadrequest.add name, uploadcontrol
loop to next object
boundarypos=instrb(boundarypos+lenb(boundary),requestbin,boundary)
loop
end sub
string to byte string conversion
function getbytestring(stringstr)
for i = 1 to len(stringstr)
char = mid(stringstr,i,1)
getbytestring = getbytestring & chrb(ascb(char))
next
end function
byte string to string conversion
function getstring(stringbin)
getstring =""
for intcount = 1 to lenb(stringbin)
getstring = getstring & chr(ascb(midb(stringbin,intcount,1)))
next
end function
%>
转自asptoday
