·您的位置: 首页 » 资源教程 » 编程开发 » ASP » ASP文件上传函数库

ASP文件上传函数库

类别: ASP教程  评论数:0 总得分:0
说明:
如果你需要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
%>
-= 资 源 教 程 =-
文 章 搜 索
关键词:
类型:
范围:
纯粹空间 softpure.com
Copyright © 2006-2008 暖阳制作 版权所有
QQ: 15242663 (拒绝闲聊)  Email: faisun@sina.com
 纯粹空间 - 韩国酷站|酷站欣赏|教程大全|资源下载|免费博客|美女壁纸|设计素材|技术论坛   Valid XHTML 1.0 Transitional
百度搜索 谷歌搜索 Alexa搜索 | 粤ICP备19116064号-1