RSS
热门关键字:
当前位置 :| 主页>美工设计>WEB标准>

无组件上传怎样控制文件格式?怎样得到文件的后辍名?

来源:网络 作者:佚名 时间:2008-09-03 Tag: 点击:

dim contentlen
contentlen=request.totalbytes
''接收到的文件的大小

if contentlen>102400 then
response.write "文件太大,超过100k,不允许上传。请返回"
else

dim content
content=request.binaryread(request.totalbytes)
''接收到的文件大小用字节表示


''二进制相互转换
Function getByteString(StringStr)
getByteString=""
For i=1 to Len(StringStr)
char=Mid(StringStr,i,1)
getByteString=getByteString&chrB(AscB(char))
Next
End Function
Function getString(StringBin)
getString =""
For intCount = 1 to LenB(StringBin)
getString = getString & chr(AscB(MidB(StringBin,intCount,1)))
Next
End Function

dim upbeg,upend,lineone,linetwo,linethree,line1,line2,line3
upbeg=1
upend=instrb(upbeg,content,getbytestring(chr(10)))
lineone=midb(content,upbeg,upend-upbeg)
upbeg=upend+1
line1=lenb(lineone)
upend=instrb(upbeg,content,getbytestring(chr(10)))
linetwo=midb(content,upbeg,upend-upbeg)
upbeg=upend+1
line2=lenb(linetwo)
upend=instrb(upbeg,content,getbytestring(chr(13)))
linethree=midb(content,upbeg,upend-upbeg)
line3=lenb(linethree)

''获得文件名
dim pp,checknametemp,checklen,checkname,filename
pp=instrb(1,linetwo,getbytestring(chr(46)))
checknametemp=rightb(linetwo,line2-pp+1)
checklen=instrb(1,checknametemp,getbytestring(chr(34)))
checkname=getstring(leftb(checknametemp,checklen-1))
filename=year(now)&month(now)&day(now)&hour(now)&minute(now)&second(now)&checkname

''上传文件
dim alllen,upstream,upstreamend,file
alllen=line1+line2+line3+6
set upstream=server.createobject("adodb.stream")
set upstreamend=server.createobject("adodb.stream")
upstream.type=1
upstreamend.type=1
upstream.open
upstreamend.open
upstream.write content
upstream.position=alllen
file=upstream.read(clng(contentlen-alllen-line1-5))
upstreamend.write file
upstreamend.savetofile(server.mappath("uploadimg/"&filename))
path="uploadimg/"&filename
sql="insert into path (url) values (''"&path&"'')"
cn.execute(sql)
''目录路径修改
upstream.close
upstreamend.close
set upstream=nothing
set upstreamend=nothing

right(filename, 4) 来判断, 因为一般扩展名都是 3 位
如:

if right(lcase(filename), 4) <> ".jpg" then
  response.write "只能上传 jpg 图片"
  response.end
end if


最新评论共有 0 位网友发表了评论
发表评论
评论内容:不能超过250字,需审核,请自觉遵守互联网相关政策法规。
用户名: 密码:
匿名?
注册