2个回答
展开全部
这是我自己按无惧改的,只能上传jpg的,你可以改
<%
If Request.TotalBytes < 1 Then '如果没有数据上传
response.write "请先选择你要上传的文件!"
response.End()
End If
If Request.TotalBytes > 1024*1024 Then
response.write "你上传的文件总大小超出了最大限制(1M)"
response.End()
End If
call upload
sub upload()
dim bCrLf,sSpace,iStart ,iInfoEnd,iFormStart,iFindStart ,iFindEnd,sFileName,FileName,FilePath, FileExt
Set tStream = Server.CreateObject ("ADODB.Stream")
Set oUpFileStream = Server.CreateObject ("ADODB.Stream")
oUpFileStream.Type = 1
oUpFileStream.Mode = 3
oUpFileStream.Open
oUpFileStream.Write Request.BinaryRead (Request.TotalBytes)
oUpFileStream.Position = 0
RequestBinData = oUpFileStream.Read
iFormEnd = oUpFileStream.Size'所有读取的数据大小
bCrLf = ChrB (13) & ChrB (10)'取得每个项目之间的分隔符
sSpace = MidB (RequestBinData,1, InStrB (1,RequestBinData,bCrLf)-1)'取得第一个分割线的内容
iStart = LenB (sSpace) '读取-----------------------------7d71e42c1060a的长度
iFormStart = iStart+2 '到-----------------------------7d71e42c1060a后的位置
iInfoEnd = InStrB (iFormStart,RequestBinData,bCrLf & bCrLf)+3'到Content-Disposition: form-data; name="FileName"; filename=""Content-Type: application/octet-stream的位置
tStream.Type = 1
tStream.Mode = 3
tStream.Open
oUpFileStream.Position = iFormStart
oUpFileStream.CopyTo tStream,iInfoEnd-iFormStart
tStream.Position = 0
tStream.Type = 2
tStream.CharSet = "gb2312"
sInfo = tStream.ReadText
iFindStart = InStr (22,sInfo,"name=""",1)+6 '读取name="的位置,相对sInfo
iFindEnd = InStr (iFindStart,sInfo,"""",1)'读取name=""的位置,相对sInfo
sFormName = Mid (sinfo,iFindStart,iFindEnd-iFindStart)'读取name=的内容
iFindStart = InStr (iFormStart+1,sInfo,"filename=""",1)+10'读取filename="的位置,相对sInfo
iFindEnd = InStr (iFindStart,sInfo,"""",1)'读取filename=""的位置,相对sInfo
sFileName = Mid (sinfo,iFindStart,iFindEnd-iFindStart)'读取filename=的内容
FileName = Mid (sFileName,InStrRev (sFileName, "\")+1)'取得文件名
FilePath = Left (sFileName,InStrRev (sFileName, "\"))'取得文件路径
FileExt = Mid (sFileName,InStrRev (sFileName, ".")+1)'取得文件格式
tStream.Close
Set tStream = Nothing
if sFormName<>"zxtzx" then
response.Write "上传错误!"
response.End()
end if
if fileExt<>"jpg" then
response.Write "你上传得格式不对~必须是jpg格式的图片"
response.End()
end if
iFormStart2 = InStrB (iInfoEnd,RequestBinData,sSpace)-1'读取下一个分割线的位置
FileSize=iFormStart2 -iInfoEnd
filename="uploadfile/"&session("id")&".jpg"
Set oFileStream = CreateObject ("ADODB.Stream")
oFileStream.Type = 1
oFileStream.Mode = 3
oFileStream.Open
oUpFileStream.Position = iInfoEnd
oUpFileStream.CopyTo oFileStream,FileSize
oFileStream.SaveToFile Server.mappath(FileName) ,2
if err=0 then
response.Write "成功"
else
response.Write "上传失败"
end if
oFileStream.Close
Set oFileStream = Nothing
oUpFileStream.Close
Set oUpFileStream = Nothing
end sub
%>
<%
If Request.TotalBytes < 1 Then '如果没有数据上传
response.write "请先选择你要上传的文件!"
response.End()
End If
If Request.TotalBytes > 1024*1024 Then
response.write "你上传的文件总大小超出了最大限制(1M)"
response.End()
End If
call upload
sub upload()
dim bCrLf,sSpace,iStart ,iInfoEnd,iFormStart,iFindStart ,iFindEnd,sFileName,FileName,FilePath, FileExt
Set tStream = Server.CreateObject ("ADODB.Stream")
Set oUpFileStream = Server.CreateObject ("ADODB.Stream")
oUpFileStream.Type = 1
oUpFileStream.Mode = 3
oUpFileStream.Open
oUpFileStream.Write Request.BinaryRead (Request.TotalBytes)
oUpFileStream.Position = 0
RequestBinData = oUpFileStream.Read
iFormEnd = oUpFileStream.Size'所有读取的数据大小
bCrLf = ChrB (13) & ChrB (10)'取得每个项目之间的分隔符
sSpace = MidB (RequestBinData,1, InStrB (1,RequestBinData,bCrLf)-1)'取得第一个分割线的内容
iStart = LenB (sSpace) '读取-----------------------------7d71e42c1060a的长度
iFormStart = iStart+2 '到-----------------------------7d71e42c1060a后的位置
iInfoEnd = InStrB (iFormStart,RequestBinData,bCrLf & bCrLf)+3'到Content-Disposition: form-data; name="FileName"; filename=""Content-Type: application/octet-stream的位置
tStream.Type = 1
tStream.Mode = 3
tStream.Open
oUpFileStream.Position = iFormStart
oUpFileStream.CopyTo tStream,iInfoEnd-iFormStart
tStream.Position = 0
tStream.Type = 2
tStream.CharSet = "gb2312"
sInfo = tStream.ReadText
iFindStart = InStr (22,sInfo,"name=""",1)+6 '读取name="的位置,相对sInfo
iFindEnd = InStr (iFindStart,sInfo,"""",1)'读取name=""的位置,相对sInfo
sFormName = Mid (sinfo,iFindStart,iFindEnd-iFindStart)'读取name=的内容
iFindStart = InStr (iFormStart+1,sInfo,"filename=""",1)+10'读取filename="的位置,相对sInfo
iFindEnd = InStr (iFindStart,sInfo,"""",1)'读取filename=""的位置,相对sInfo
sFileName = Mid (sinfo,iFindStart,iFindEnd-iFindStart)'读取filename=的内容
FileName = Mid (sFileName,InStrRev (sFileName, "\")+1)'取得文件名
FilePath = Left (sFileName,InStrRev (sFileName, "\"))'取得文件路径
FileExt = Mid (sFileName,InStrRev (sFileName, ".")+1)'取得文件格式
tStream.Close
Set tStream = Nothing
if sFormName<>"zxtzx" then
response.Write "上传错误!"
response.End()
end if
if fileExt<>"jpg" then
response.Write "你上传得格式不对~必须是jpg格式的图片"
response.End()
end if
iFormStart2 = InStrB (iInfoEnd,RequestBinData,sSpace)-1'读取下一个分割线的位置
FileSize=iFormStart2 -iInfoEnd
filename="uploadfile/"&session("id")&".jpg"
Set oFileStream = CreateObject ("ADODB.Stream")
oFileStream.Type = 1
oFileStream.Mode = 3
oFileStream.Open
oUpFileStream.Position = iInfoEnd
oUpFileStream.CopyTo oFileStream,FileSize
oFileStream.SaveToFile Server.mappath(FileName) ,2
if err=0 then
response.Write "成功"
else
response.Write "上传失败"
end if
oFileStream.Close
Set oFileStream = Nothing
oUpFileStream.Close
Set oUpFileStream = Nothing
end sub
%>
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询