原创的ASP文件上传函数库,比动网、amao的都差了很多,不过是学习的好资料
54powerman
说明:
如果你需要file表单的串值,用GetFullName("file")
如果需要file表单的文件名,用GetFileName("file")
如果需要file表单的扩展名,用GetExtName("file")
如果需要普通文本表单的值,用MyRequest("password")
如果需要file表单的二进制值,也是用MyRequest("file")
保存文件用SaveFile("file","myUpload.jpg")
写入数据库的格式:
Rs.AppandChunk MyRequest("file")
<%
'Program:54powerman
'EMail & MSN:54powerman@163.com
'QQ:19486554
'初始化数据
Response.buffer=true
FormData = Request.BinaryRead(Request.TotalBytes)
bncrlf = ChrB(13)&ChrB(10)
Set sr=CreateObject("Adodb.Stream")
sr.Mode=3
sr.Type=1
sr.Open
sr.Write FormData
Init=sr
'常用函数
Function Str2B(Str)
For i = 1 To len(Str)
Str2B = Str2B&ChrB(Asc(Mid(Str,i,1)))
Next
End Function
Function B2Str(Str)
For i = 1 To LenB(Str)
ThisCharCode = AscB(MidB(Str,i,1))
If ThisCharCode < &H80 Then
B2Str = B2Str & Chr(ThisCharCode)
Else
NextCharCode = AscB(MidB(Str,i+1,1))
B2Str = B2Str & Chr(CLng(ThisCharCode) * &H100 + CInt(NextCharCode))
i = i + 1
End If
Next
End Function
Function MyRequest(FormName)
divider = leftb(FormData,inStrb(FormData,bncrlf)-1)
Cur = inStrb(FormData,Str2B("name=")&ChrB(34)&Str2B(FormName)&ChrB(34))
MyRequest=null
DataStart=inStrb(Cur,FormData,bncrlf&bncrlf)+4
DataEnd = inStrb(DataStart+1,FormData,divider)-DataStart
TempStr = Midb(FormData,Cur,DataStart)
If inStrb(TempStr,Str2B("filename=")) Then
MyRequest = Midb(FormData,DataStart,DataEnd)
else
MyRequest = B2Str(Midb(FormData,DataStart,DataEnd))
End If
End Function
Function GetFullName(FormName)
divider = leftb(FormData,inStrb(FormData,bncrlf)-1)
Cur = inStrb(FormData,Str2B("name=")&ChrB(34)&Str2B(FormName)&ChrB(34))
DataStart=inStrb(Cur,FormData,Str2B("filename="))+10
DataEnd = inStrb(DataStart+1,FormData,ChrB(34))-DataStart
TempStr = Midb(FormData,Cur,DataStart)
GetFullName = B2Str(Midb(FormData,DataStart,DataEnd))
End Function
Function GetFileName(FormName)
FullName=GetFullName(FormName)
GetFileName = Mid(FullName,InStrRev(FullName,"\")+1)
End Function
Function GetExpName(FormName)
GetExpName = Mid(GetFileName(FormName),InStrRev(GetFileName(FormName),".")+1)
End Function
Function SaveFile(FormName,FileName)
divider = leftb(FormData,inStrb(FormData,bncrlf)-1)
Cur = inStrb(FormData,Str2B("name=")&ChrB(34)&Str2B(FormName)&ChrB(34))
SaveFile=false
DataStart=inStrb(Cur,FormData,bncrlf&bncrlf)+4
DataEnd = inStrb(DataStart+1,FormData,divider)-DataStart
set dr=CreateObject("Adodb.Stream")
dr.Mode=3
dr.Type=1
dr.Open
sr.Position=DataStart-1
sr.CopyTo dr,DataEnd
dr.SaveToFile FileName,2
sr.Close
set sr=nothing
dr.Close
set dr=nothing
SaveFile=true
End Function
Function FileSize(FormName)
divider = leftb(FormData,inStrb(FormData,bncrlf)-1)
Cur = inStrb(FormData,Str2B("name=")&ChrB(34)&Str2B(FormName)&ChrB(34))
FileSize=0
DataStart=inStrb(Cur,FormData,bncrlf&bncrlf)+4
FileSize = inStrb(DataStart+1,FormData,divider)-DataStart-2
End Function
%>