预览模式: 普通 | 列表

Asp判断本地文件是否是图片格式

function CheckFileType(filename) 
on error resume next 
CheckFileType=false 
dim fstream,fileExt,stamp,i 
fileExt=mid(filename,InStrRev(filename,".")+1) 
set fstream=Server.createobject("ADODB.Stream") 
fstream.Open 
fstream.Type=adTypeBinary 
fstream.LoadFromFile filename 
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 CheckFileType=true else CheckFileType=false 
next 
case "gif" 
stamp=fstream.read(6) 
for i=0 to 5 
if ascB(MidB(stamp,i+1,1))=gif(i) then CheckFileType=true else CheckFileType=false 
next 
case "png" 
stamp=fstream.read(4) 
for i=0 to 3 
if ascB(MidB(stamp,i+1,1))=png(i) then CheckFileType=true else CheckFileType=false 
next 
case "bmp" 
stamp=fstream.read(2) 
for i=0 to 1 
if ascB(MidB(stamp,i+1,1))=bmp(i) then CheckFileType=true else CheckFileType=false 
next 
end select 
fstream.Close 
set fseteam=nothing 
if err.number<>0 then CheckFileType=false 
end function

Tags: asp

分类:技术文章 | 固定链接 | 评论: 0 | 引用: 0 | 查看次数: 3418

 广告位

↑返回顶部↑