<%
If Request.TotalBytes>0 Then
Call upFileSave()
Else
Call upFileForm()
End If
Function BinToStr(Bin)
Dim i, str
Dim clow
For i = 1 To LenB(Bin)
clow = MidB(Bin, i, 1)
If AscB(clow) < 128 Then
str = str & Chr(AscB(clow))
Else
i = i + 1
If i <= LenB(Bin) Then str = str & Chr(AscW(MidB(Bin, i, 1) & clow))
End If
Next
BinToStr = str
End Function
Sub upFileSave()
Dim FormData, FormSize, DataStart, CLStr, DivStr, DataSize, SavePath, ExpName, SaveFileName
Dim FileObj, SaveObj, ReadSize, GetData, SaveData, ChunkBytes, reQHeader, reQFileName
'SavePath上传文件保存位置,如../upfile/
SavePath = ""
FormSize =Request.TotalBytes
ReadSize =0
ChunkBytes = 64 *1024
SaveFileName = Replace(Replace(Replace(Now, " ", ""), ":", ""), "-", "")
Set FileObj = Server.CreateObject("ADODB.Stream")
FileObj.Mode = 3
FileObj.Type = 1
FileObj.Open
Do While ReadSize < FormSize
GetData = Request.BinaryRead(ChunkBytes)
FileObj.Position = ReadSize
FileObj.Write GetData
ReadSize = ReadSize + ChunkBytes
If ReadSize > FormSize Then ReadSize = FormSize
Loop
'开始计算
FileObj.Position =0
FormData = FileObj.Read
CLStr =ChrB(13) & ChrB(10)
DataStart =InStrB(FormData,CLStr & CLStr)+3
DivStr =LeftB(FormData,InStrB(FormData,CLStr)-1)
DataSize =InStrB(DataStart+1,FormData,DivStr)-DataStart-2
reQHeader = BinToStr(LeftB(FormData, DataStart))
FileObj.Position =DataStart
reQFileName = Mid(reQHeader, InstrRev(reQHeader, "\")+1)
reQFileName = Mid(reQFileName, 1, InstrRev(reQFileName, Chr(34))-1)
'过滤文件类型
ExpName = LCase(Right(reQFileName, 4))
If Instr(".gif.jpg.bmp.png", ExpName) =0 Then
Response.Write("只允许上传gif/jpg/bmp/png格式文件,<a href=### Onclick='history.go(-1)'>点这里返回</a>")
FileObj.Close
Set FileObj = Nothing
Response.End()
End If
'创建新实例
Set SaveObj = Server.CreateObject("ADODB.Stream")
With SaveObj
.Mode =3
.Type =1
.Open
End With
FileObj.CopyTo SaveObj, DataSize
SaveFileName = SavePath & SaveFileName & Mid(reQFileName, InstrRev(reQFileName, "."))
SaveObj.SaveToFile Server.MapPath(SaveFileName), 2
SaveObj.Close
Set SaveObj = Nothing
FileObj.Close
Set FileObj = Nothing
Response.Write("上传成功,<a href=### Onclick='history.go(-1)'>点这里继续上传</a><hr>源 文 件:"& reQFileName &"<BR>目标文件:"& SaveFileName &"<BR>文件大小:"& DataSize)
End Sub
Sub upFileForm()
%>
<style type="text/css">
<!--
body {
margin-left: 0px;
margin-top: 0px;
margin-right: 0px;
margin-bottom: 0px;
}
-->
</style>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<form name="form1" enctype="multipart/form-data" method="post" action="UpFile.Asp">
<tr>
<td>
<input name="file" type="file" size="20">
<input type="submit" name="Submit" value="确定上传">
</td>
</tr>
</form>
</table>
<% End Sub %>
If Request.TotalBytes>0 Then
Call upFileSave()
Else
Call upFileForm()
End If
Function BinToStr(Bin)
Dim i, str
Dim clow
For i = 1 To LenB(Bin)
clow = MidB(Bin, i, 1)
If AscB(clow) < 128 Then
str = str & Chr(AscB(clow))
Else
i = i + 1
If i <= LenB(Bin) Then str = str & Chr(AscW(MidB(Bin, i, 1) & clow))
End If
Next
BinToStr = str
End Function
Sub upFileSave()
Dim FormData, FormSize, DataStart, CLStr, DivStr, DataSize, SavePath, ExpName, SaveFileName
Dim FileObj, SaveObj, ReadSize, GetData, SaveData, ChunkBytes, reQHeader, reQFileName
'SavePath上传文件保存位置,如../upfile/
SavePath = ""
FormSize =Request.TotalBytes
ReadSize =0
ChunkBytes = 64 *1024
SaveFileName = Replace(Replace(Replace(Now, " ", ""), ":", ""), "-", "")
Set FileObj = Server.CreateObject("ADODB.Stream")
FileObj.Mode = 3
FileObj.Type = 1
FileObj.Open
Do While ReadSize < FormSize
GetData = Request.BinaryRead(ChunkBytes)
FileObj.Position = ReadSize
FileObj.Write GetData
ReadSize = ReadSize + ChunkBytes
If ReadSize > FormSize Then ReadSize = FormSize
Loop
'开始计算
FileObj.Position =0
FormData = FileObj.Read
CLStr =ChrB(13) & ChrB(10)
DataStart =InStrB(FormData,CLStr & CLStr)+3
DivStr =LeftB(FormData,InStrB(FormData,CLStr)-1)
DataSize =InStrB(DataStart+1,FormData,DivStr)-DataStart-2
reQHeader = BinToStr(LeftB(FormData, DataStart))
FileObj.Position =DataStart
reQFileName = Mid(reQHeader, InstrRev(reQHeader, "\")+1)
reQFileName = Mid(reQFileName, 1, InstrRev(reQFileName, Chr(34))-1)
'过滤文件类型
ExpName = LCase(Right(reQFileName, 4))
If Instr(".gif.jpg.bmp.png", ExpName) =0 Then
Response.Write("只允许上传gif/jpg/bmp/png格式文件,<a href=### Onclick='history.go(-1)'>点这里返回</a>")
FileObj.Close
Set FileObj = Nothing
Response.End()
End If
'创建新实例
Set SaveObj = Server.CreateObject("ADODB.Stream")
With SaveObj
.Mode =3
.Type =1
.Open
End With
FileObj.CopyTo SaveObj, DataSize
SaveFileName = SavePath & SaveFileName & Mid(reQFileName, InstrRev(reQFileName, "."))
SaveObj.SaveToFile Server.MapPath(SaveFileName), 2
SaveObj.Close
Set SaveObj = Nothing
FileObj.Close
Set FileObj = Nothing
Response.Write("上传成功,<a href=### Onclick='history.go(-1)'>点这里继续上传</a><hr>源 文 件:"& reQFileName &"<BR>目标文件:"& SaveFileName &"<BR>文件大小:"& DataSize)
End Sub
Sub upFileForm()
%>
<style type="text/css">
<!--
body {
margin-left: 0px;
margin-top: 0px;
margin-right: 0px;
margin-bottom: 0px;
}
-->
</style>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<form name="form1" enctype="multipart/form-data" method="post" action="UpFile.Asp">
<tr>
<td>
<input name="file" type="file" size="20">
<input type="submit" name="Submit" value="确定上传">
</td>
</tr>
</form>
</table>
<% End Sub %>