[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 = 14 + 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
%>
1、用户界面:
代码如下:
function checkall(form)
{for (var i=0;i