'作 用: 检测上传的图片文件(jpeg,gif,bmp,png)是否真的为图片
'函数名: TrueStr(fileTrue)
'参 数: sFileName 文件名(此处文件名是文件夹的物理全路径)
'返回值: 确实为图片文件则返回 True ,否则返回False
'*******************************************************
function IsImgFile(sFileName)
const adTypeBinary=1
dim return
dim jpg(1):jpg(0)=CByte(&HFF):jpg(1)=CByte(&HD8)
dim bmp(1):bmp(0)=CByte(&H42):bmp(1)=CByte(&H4D)
dim png(3):png(0)=CByte(&H89):png(1)=CByte(&H50):png(2)=CByte(&H4E):png(3)=CByte(&H47)
dim gif(5):gif(0)=CByte(&H47):gif(1)=CByte(&H49):gif(2)=CByte(&H46):gif(3)=CByte(&H39):gif(4)=CByte(&H38):gif(5)=CByte(&H61)
on error resume next
return=false
dim fstream,fileExt,stamp,i
'得到文件后缀并转化为小写
FileExt = LCase(GetFileExt(sFileName))
'如果文件后缀为 jpg,jpeg,bmp,gif,png 中的任一种
'则执行真实图片判断
if strInString(FileExt,"jpg|jpeg|bmp|gif|png")=true then
Set fstream=Server.createobject("ADODB.Stream")
fstream.Open
fstream.Type=adTypeBinary
fstream.LoadFromFile sFileName
fstream.position=0
select case LCase(FileExt)
case "jpg","jpeg"
stamp=fstream.read(2)
for i=0 to 1
if ascB(MidB(stamp,i+1,1))=jpg(i) then return=true else return=false
next
case "gif"
stamp=fstream.read(6)
for i=0 to 5
if ascB(MidB(stamp,i+1,1))=gif(i) then return=true else return=false
next
case "png"
stamp=fstream.read(4)
for i=0 to 3
if ascB(MidB(stamp,i+1,1))=png(i) then return=true else return=false
next
case "bmp"
stamp=fstream.read(2)
for i=0 to 1
if ascB(MidB(stamp,i+1,1))=bmp(i) then return=true else return=false
next
End select
fstream.Close
Set fseteam=nothing
if err.number<>0 then return = false
else
return = true
End if
IsImgFile = return
End function





