ASP技巧实例:关于对表单操作的程序
2007-09-25 12:05:02 来源:WEB开发网InsertingFormcontentintoDatabasewithASP.
<%
'--Loader.asp--
'--version1.5.2
'--lastupdated12/5/2002
'
'FaisalKhan
'faisal@stardeveloper.com
'www.stardeveloper.com
'Classforhandlingbinaryuploads
ClassLoader
Privatedict
PrivateSubClass_Initialize
Setdict=Server.CreateObject("Scripting.Dictionary")
EndSub
PrivateSubClass_Terminate
IfIsObject(intDict)Then
intDict.RemoveAll
SetintDict=Nothing
EndIf
IfIsObject(dict)Then
dict.RemoveAll
Setdict=Nothing
EndIf
EndSub
PublicPropertyGetCount
Count=dict.Count
EndProperty
PublicSubInitialize
IfRequest.TotalBytes>0Then
DimbinData
binData=Request.BinaryRead(Request.TotalBytes)
getDatabinData
EndIf
EndSub
PublicFunctiongetFileData(name)
Ifdict.Exists(name)Then
getFileData=dict(name).Item("Value")
Else
getFileData=""
EndIf
EndFunction
PublicFunctiongetValue(name)
Dimgv
Ifdict.Exists(name)Then
gv=CStr(dict(name).Item("Value"))
gv=Left(gv,Len(gv)-2)
getValue=gv
Else
getValue=""
EndIf
EndFunction
PublicFunctionsaveToFile(name,path)
Ifdict.Exists(name)Then
Dimtemp
temp=dict(name).Item("Value")
Dimfso
Setfso=Server.CreateObject("Scripting.FileSystemObject")
Dimfile
Setfile=fso.CreateTextFile(path)
FortPoint=1toLenB(temp)
file.WriteChr(AscB(MidB(temp,tPoint,1)))
Next
file.Close
saveToFile=True
Else
saveToFile=False
EndIf
EndFunction
PublicFunctiongetFileName(name)
Ifdict.Exists(name)Then
Dimtemp,tempPos
temp=dict(name).Item("FileName")
tempPos=1+InStrRev(temp,"")
getFileName=Mid(temp,tempPos)
Else
getFileName=""
EndIf
EndFunction
PublicFunctiongetFilePath(name)
Ifdict.Exists(name)Then
Dimtemp,tempPos
temp=dict(name).Item("FileName")
tempPos=InStrRev(temp,"")
getFilePath=Mid(temp,1,tempPos)
Else
getFilePath=""
EndIf
EndFunction
PublicFunctiongetFilePathComplete(name)
Ifdict.Exists(name)Then
getFilePathComplete=dict(name).Item("FileName")
Else
getFilePathComplete=""
EndIf
EndFunction
PublicFunctiongetFileSize(name)
Ifdict.Exists(name)Then
getFileSize=LenB(dict(name).Item("Value"))
Else
getFileSize=0
EndIf
EndFunction
PublicFunctiongetFileSizeTranslated(name)
Ifdict.Exists(name)Then
temp=LenB(dict(name).Item("Value"))
Iftemp<=1024Then
getFileSizeTranslated=temp&"bytes"
Else
temp=FormatNumber((temp/1024),2)
getFileSizeTranslated=temp&"kilobytes"
EndIf
Else
getFileSizeTranslated=""
EndIf
EndFunction
PublicFunctiongetContentType(name)
Ifdict.Exists(name)Then
getContentType=dict(name).Item("ContentType")
Else
getContentType=""
EndIf
EndFunction
PrivateSubgetData(rawData)
Dimseparator
separator=MidB(rawData,1,InstrB(1,rawData,ChrB(13))-1)
DimlenSeparator
lenSeparator=LenB(separator)
DimcurrentPos
currentPos=1
DiminStrByte
inStrByte=1
Dimvalue,mValue
DimtempValue
tempValue=""
WhileinStrByte>0
inStrByte=InStrB(currentPos,rawData,separator)
mValue=inStrByte-currentPos
IfmValue>1Then
value=MidB(rawData,currentPos,mValue)
DimbegPos,endPos,midValue,nValue
DimintDict
SetintDict=Server.CreateObject("Scripting.Dictionary")
begPos=1+InStrB(1,value,ChrB(34))
endPos=InStrB(begPos+1,value,ChrB(34))
nValue=endPos
DimnameN
nameN=MidB(value,begPos,endPos-begPos)
DimnameValue,isValid
isValid=True
IfInStrB(1,value,stringToByte("Content-Type"))>1Then
begPos=1+InStrB(endPos+1,value,ChrB(34))
endPos=InStrB(begPos+1,value,ChrB(34))
IfendPos=0Then
endPos=begPos+1
isValid=False
EndIf
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)))
EndIf
IfisValid=TrueThen
intDict.Add"Value",nameValue
intDict.Add"Name",nameN
dict.AddbyteToString(nameN),intDict
EndIf
EndIf
currentPos=lenSeparator+inStrByte
Wend
EndSub
EndClass
PrivateFunctionstringToByte(toConv)
DimtempChar
Fori=1toLen(toConv)
tempChar=Mid(toConv,i,1)
stringToByte=stringToByte&chrB(AscB(tempChar))
Next
EndFunction
PrivateFunctionbyteToString(toConv)
Fori=1toLenB(toConv)
byteToString=byteToString&Chr(AscB(MidB(toConv,i,1)))
Next
EndFunction
%>
- ››asp.net页面弄成伪静态页面
- ››Asp.net 中将汉字转换成拼音的方法
- ››ASP.NET及JS中的cookie基本用法
- ››ASP.NET获取MS SQL Server安装实例
- ››asp.net实现调用百度pai 在线翻译英文转中文
- ››ASP.NET页面选项进行提示判断
- ››Asp.net定时执行程序
- ››ASP.NET中利用DataList实现图片无缝滚动
- ››ASP.NET验证控件RequiredFieldValidator
- ››ASP.NET中使用System.Net.Mail发邮件
- ››ASP.NET中获取用户控件中控件的ID
- ››ASP.NET中FileBytes写成文件并存档
更多精彩
赞助商链接