Code代码片断(5do8)

FSO正则ADO内置对象基础语法

新主题
判断图片是否合法
说话自由

首页 » ASP » 内置对象 »

判断图片是否合法

标签: CByte
jpg(0)=CByte(&HFF)
jpg(1)=CByte(&HD8)
bmp(0)=CByte(&H42):bmp(1)=CByte(&H4D)
png(0)=CByte(&H89):png(1)=CByte(&H50):png(2)=CByte(&H4E):png(3)=CByte(&H47)
gif(0)=CByte(&H47):gif(1)=CByte(&H49):gif(2)=CByte(&H46)
gif(3)=CByte(&H38):gif(4)=CByte(&H39):gif(5)=CByte(&H61)
'判断是否为有效图片类型
  function imageType()
on error resume next
Set fstream = CreateObject("Adodb.Stream")
fstream.Mode = 1
fstream.Type = 1
fstream.Open
DoteyUpload_SourceData.position = FileStart
DoteyUpload_SourceData.copyto fstream, FileSize

fstream.position=0
select case FileExt
case ".jpg",".jpeg"
stamp=fstream.read(2)
for i=0 to 1
if ascB(MidB(stamp,i+1,1))=jpg(i) then imageType=true else imageType=false
next
case ".gif"
stamp=fstream.read(6)
for i=0 to 5
if ascB(MidB(stamp,i+1,1))=gif(i) then imageType=true else imageType=false
next
case ".png"
stamp=fstream.read(4)& "<br/>"
for i=0 to 3
if ascB(MidB(stamp,i+1,1))=png(i) then imageType=true else imageType=false
next
case ".bmp"
stamp=fstream.read(2)& "<br/>"
for i=0 to 1
if ascB(MidB(stamp,i+1,1))=bmp(i) then imageType=true else imageType=false
next
end select

fstream.Close
set fstream=nothing
if err.number<>0 then imageType=false
   end function

ccdot写于2008-9-17 13:37:33

如果愿意,请留下你观点或者感受...
称呼*
内容*
验证码*