''列出所有上传了的文件
for each formName in upload.objFile
set file=upload.file(formName)
''''限制文件格式
fileExt=lcase(right(file.filename,4))
Forum_upload="gif,jpg,jpeg,png"
Forumupload=split(Forum_upload,",")
for i=0 to ubound(Forumupload)
if fileEXT="."&trim(Forumupload(i)) then
uploadsuc=true
exit for
else
uploadsuc=false
end if
next
if uploadsuc=false then
response.write "<font size=2>文件格式限制[<a href=# onclick=history.go(-1)>请重新上传</a>]</font>"
response.end
end If
'''''''''''''''
if file.filesize>0 then 作者: sisghoul 时间: 2011-1-4 15:56
这个是检查头文件判断类型的
<% Rem Designer:ZMM
If Request.ServerVariables("REQUEST_METHOD")="POST" Then
Function GetByteString(str)
For i=1 To Len(str)
GetByteString = GetByteString & ChrB(Asc(Mid(str, i, 1)))
Next
End Function
Dim vbCRLFbyte, i, formLength, formContent, formStream, pathStart, pathEnd, pathLength, pathContent, formText, fileStart, fileEnd, fileLength, regEx, Matches, contentType, fileType, fileExtension, fileName, fileStreamGet, fileStreamPut
Const adTypeBinary = 1
Const adTypeText = 2
vbCRLFbyte = GetByteString(vbCRLF & vbCRLF)
formLength = Request.TotalBytes
formContent = Request.BinaryRead(formLength)
Set formStream = Server.CreateObject("ADODB.Stream")
formStream.Type = adTypeText
formStream.Mode = 3
formStream.Open
formStream.WriteText formContent
formStream.Position = 0
formStream.CharSet = "GB2312"
formText = formStream.ReadText
formStream.Close
Set formStream = Nothing
Rem 获取文件头
Set regEx = New RegExp
regEx.Pattern = "\sContent-Type:\s+(.*?)\s"
regEx.Global = True
regEx.IgnoreCase = True
Set Matches = regEx.Execute(formText)
Set regEx = Nothing
contentType = Replace(Mid(Matches(0).Value, 1, Len(Matches(0).Value) - 1), "Content-Type: ", "")
fileType = Split(contentType, "/", -1, 1)(1)
看了你的代码,还没看出哪里出问题了,建议你在几个节点上加断点,用respone反馈一下结果就比较容易查到问题所在了:
1. 在fileExt=lcase(right(file.filename,4))之后显示一下fileExt的值
2. 在 if fileEXT="."&trim(Forumupload(i)) then 下显示 i 和 "."&trim(Forumupload(i)) 后的结果,可以把"."&trim(Forumupload(i)) 先赋值到一个变量,再到if语句里面做比较,这样比较直观。
另外,建议:
1. 把 Forum_upload="gif,jpg,jpeg,png" 和 Forumupload=split(Forum_upload,",")都放到 for each formName in upload.objFile之上,这个过程只需做一次就可以了,不需要在循环里面做;
2. 把下面的代码
for i=0 to ubound(Forumupload)
if fileEXT="."&trim(Forumupload(i)) then
uploadsuc=true
exit for
else
uploadsuc=false
end if
next
改为
uploadsuc=false
for i=0 to ubound(Forumupload)
if fileEXT="."&trim(Forumupload(i)) then
uploadsuc=true
exit for
end if
next 作者: kennywae 时间: 2011-1-4 18:44