28,390
社区成员
发帖
与我相关
我的任务
分享
<!-- #include file="Upload1.asp" -->
<!-- #include file="conn1.asp" -->
<%
Server.ScriptTimeout =20*60 '上传超时时间20分钟
dim userfilepath,userfilepath1,userfilepath2
formPath = "UploadFiles/"
Set upload= New DoteyUpload
Upload.SaveTo(formPath) '将文件根据其文件名统一保存在某路径下
If upload.ErrMsg = "" then
Response.Write ("form传递来的数据:<BR>")
For each formName in upload.Form ''列出所有form数据
temp=temp & "||" & upload.Form(formName) '用字符串存表单所有变量
next
temp2=split(temp,"||") '将字符串拆开存入数组
username=temp2(1)
name=temp2(2)
sex=temp2(3)
postcode=temp2(4)
mailaddress=temp2(5)
accountaddress=temp2(6)
vocational=temp2(7)
position=temp2(8)
homephone=temp2(9)
email=temp2(10)
telephone=temp2(11)
fax=temp2(12)
mobile=temp2(13)
cardnumber=temp2(14)
bankaccount=temp2(15)
reservebankaccount=temp2(16)
reservenote=temp2(17)
i=1
Response.Write ("<BR><BR>已经成功上传文件:<BR>")
set rs=server.createobject("adodb.recordset")
For Each formName In upload.Files ''列出所有上传了的文件
Set file = upload.Files(formName) ''生成一个文件对象
userfilepath=formPath & File.FileName
'判断
select case i
case 1
rs.open "submit",conn,1,3
rs.addnew
rs("username")=username
rs("name")=name
rs("sex")=sex
rs("postcode")=postcode
rs("mailaddress")=mailaddress
rs("accountaddress")=accountaddress
rs("vocational")=vocational
rs("position")=position
rs("homephone")=homephone
rs("email")=email
rs("telephone")=telephone
rs("fax")=fax
rs("mobile")=mobile
rs("cardnumber")=cardnumber
rs("bankaccount")=bankaccount
rs("reservebankaccount")=reservebankaccount
rs("reservenote")=reservenote
rs("ddate")=now()
rs("userfilepath").value=userfilepath
response.write "<hr>"
rs.update
rs.close
SQL="select top 1 id from submit ORDER BY ID DESC"
rs.open SQL,conn,1,3
MaxID = rs("ID")
rs.close
case 2
sql="select * from submit where id="&MaxID
rs.open sql,conn,1,3
rs("userfilepath1").value=userfilepath
response.write "<hr>"
rs.update
rs.close
case 3
sql="select * from submit where id="&MaxID
rs.open sql,conn,1,3
rs("userfilepath2").value=userfilepath
response.write "<hr>"
rs.update
rs.close
case 4
sql="select * from submit where id="&MaxID
rs.open sql,conn,1,3
rs("userfilepath3").value=userfilepath
response.write "<hr>"
rs.update
rs.close
case 5
sql="select * from submit where id="&MaxID
rs.open sql,conn,1,3
rs("userfilepath4").value=userfilepath
response.write "<hr>"
rs.update
rs.close
end select
i=i+1
Next
Else
Response.Write("上传过程中出现错误:<br>" & Upload.ErrMsg)
End If
Set file=nothing
Set upload=nothing
conn.close()
%><style type="text/css">
<!--
body {
background-color: #00CCCC;
}
-->
</style>
[code=C#]<%
Dim DoteyUpload_SourceData
Class DoteyUpload
Public Files
Public Form
Public MaxTotalBytes
Public Version
Public ProgressID
Public ErrMsg
Private BytesRead
Private ChunkReadSize
Private Info
Private Progress
Private UploadProgressInfo
Private CrLf
Private Sub Class_Initialize()
Set Files = Server.CreateObject("Scripting.Dictionary") ' 上传文件集合
Set Form = Server.CreateObject("Scripting.Dictionary") ' 表单集合
UploadProgressInfo = "DoteyUploadProgressInfo" ' Application的Key
MaxTotalBytes = 1 *1024 *1500 ' 默认最大1500K
ChunkReadSize = 64 * 1024 ' 分块大小64K
CrLf = Chr(13) & Chr(10) ' 换行
Set DoteyUpload_SourceData = Server.CreateObject("ADODB.Stream")
DoteyUpload_SourceData.Type = 1 ' 二进制流
DoteyUpload_SourceData.Open
Version = "1.0 Beta" ' 版本
ErrMsg = "" ' 错误信息
Set Progress = New ProgressInfo
End Sub
' 将文件根据其文件名统一保存在某路径下
Public Sub SaveTo(path)
Upload() ' 上传
if right(path,1) <> "/" then path = path & "/"
' 遍历所有已上传文件
For Each fileItem In Files.Items
fileItem.SaveAs path & fileItem.FileName
Next
' 保存结束后更新进度信息
Progress.ReadyState = "complete" '上传结束
UpdateProgressInfo progressID
End Sub
' 分析上传的数据,并保存到相应集合中
Public Sub Upload ()
Dim TotalBytes, Boundary
TotalBytes = Request.TotalBytes ' 总大小
If TotalBytes < 1 Then
Raise("无数据传入")
Exit Sub
End If
If TotalBytes > MaxTotalBytes Then
Raise("您当前上传大小为" & TotalBytes/1000 & " K,最大允许为" & MaxTotalBytes/1024 & "K")
Exit Sub
End If
Boundary = GetBoundary()
If IsNull(Boundary) Then
Raise("如果form中没有包括multipart/form-data上传是无效的")
Exit Sub ''如果form中没有包括multipart/form-data上传是无效的
End If
Boundary = StringToBinary(Boundary)
Progress.ReadyState = "loading" '开始上传
Progress.TotalBytes = TotalBytes
UpdateProgressInfo progressID
Dim DataPart, PartSize
BytesRead = 0
'循环分块读取
Do While BytesRead < TotalBytes
'分块读取
PartSize = ChunkReadSize
if PartSize + BytesRead > TotalBytes Then PartSize = TotalBytes - BytesRead
DataPart = Request.BinaryRead(PartSize)
BytesRead = BytesRead + PartSize
DoteyUpload_SourceData.Write DataPart
Progress.UploadedBytes = BytesRead
Progress.LastActivity = Now()
' 更新进度信息
UpdateProgressInfo progressID
Loop
' 上传结束后更新进度信息
Progress.ReadyState = "loaded" '上传结束
UpdateProgressInfo progressID
Dim Binary
DoteyUpload_SourceData.Position = 0
Binary = DoteyUpload_SourceData.Read
Dim BoundaryStart, BoundaryEnd, PosEndOfHeader, IsBoundaryEnd
Dim Header, bFieldContent
Dim FieldName
Dim File
Dim TwoCharsAfterEndBoundary
BoundaryStart = InStrB(Binary, Boundary)
BoundaryEnd = InStrB(BoundaryStart + LenB(Boundary), Binary, Boundary, 0)
Do While (BoundaryStart > 0 And BoundaryEnd > 0 And Not IsBoundaryEnd)
' 获取表单头的结束位置
PosEndOfHeader = InStrB(BoundaryStart + LenB(Boundary), Binary, StringToBinary(vbCrLf + vbCrLf))
' 分离表单头信息,类似于:
' Content-Disposition: form-data; name="file1"; filename="G:\homepage.txt"
' Content-Type: text/plain
Header = BinaryToString(MidB(Binary, BoundaryStart + LenB(Boundary) + 2, PosEndOfHeader - BoundaryStart - LenB(Boundary) - 2))
' 分离表单内容
bFieldContent = MidB(Binary, (PosEndOfHeader + 4), BoundaryEnd - (PosEndOfHeader + 4) - 2)
FieldName = GetFieldName(Header)
' 如果是附件
If InStr (Header,"filename=""") > 0 Then
Set File = New FileInfo
' 获取文件相关信息
Dim clientPath
clientPath = GetFileName(Header)
File.FileName = GetFileNameByPath(clientPath)
File.FileExt = GetFileExt(clientPath)
File.FilePath = clientPath
File.FileType = GetFileType(Header)
File.FileStart = PosEndOfHeader + 3
File.FileSize = BoundaryEnd - (PosEndOfHeader + 4) - 2
File.FormName = FieldName
' 如果该文件不为空并不存在该表单项保存之
If Not Files.Exists(FieldName) And File.FileSize > 0 Then
Files.Add FieldName, File
End If