欢迎光临
我们一直在努力

以下代码如何修改,才能限制上传文件类型?-ASP教程,脚本编码

建站超值云服务器,限时71元/月

<%

dim formdata, formsize, divider, bcrlf

formsize = request.totalbytes

formdata = request.binaryread(formsize)

bcrlf = chrb(13) & chrb(10)

divider = leftb(formdata, instrb(formdata, bcrlf) – 1)

function savefile(formfilefield, path, maxsize, savtype)

dim streamobj,streamobj1

set streamobj = server.createobject("adodb.stream")

set streamobj1 = server.createobject("adodb.stream")

streamobj.mode = 3

streamobj1.mode = 3

streamobj.type = 1

streamobj1.type = 1

savefile = ""

startpos = lenb(divider) + 2

formfilefield = chr(34) & formfilefield & chr(34)

if right(path,1) <> "\" then

path = path & "\"

end if

do while startpos > 0

strlen = instrb(startpos, formdata, bcrlf) – startpos

searchstr = midb(formdata, startpos, strlen)

if instr(bin2str(searchstr), formfilefield) > 0 then

filename = bin2str(getfilename(searchstr,path,savtype))

if filename <> "" then

filestart = instrb(startpos, formdata, bcrlf & bcrlf) + 4

filelen = instrb(startpos, formdata, divider) – 2 – filestart

if filelen <= maxsize*1024 then

filecontent = midb(formdata, filestart, filelen)

streamobj.open

streamobj1.open

streamobj.write formdata

streamobj.position=filestart-1

streamobj.copyto streamobj1,filelen

if savtype =0 then

savtype = 1

end if

streamobj1.savetofile path & filename, savtype

streamobj.close

streamobj1.close

if savefile <> "" then

savefile = savefile & "," & filename

else

savefile = filename 显示出的文件名

end if

else

if savefile <> "" then

savefile = savefile & ",*toobig*"

else

savefile = "*toobig*"

end if

end if

end if

end if

if instrb(startpos, formdata, divider) < 1 then

exit do

end if

startpos = instrb(startpos, formdata, divider) + lenb(divider) + 2

loop

end function

function getformval(formname)

getformval = ""

startpos = lenb(divider) + 2

formname = chr(34) & formname & chr(34)

do while startpos > 0

strlen = instrb(startpos, formdata, bcrlf) – startpos

searchstr = midb(formdata, startpos, strlen)

if instr(bin2str(searchstr), formname) > 0 then

valstart = instrb(startpos, formdata, bcrlf & bcrlf) + 4

vallen = instrb(startpos, formdata, divider) – 2 – valstart

valcontent = midb(formdata, valstart, vallen)

if getformval <> "" then

getformval = getformval & "," & bin2str(valcontent)

else

getformval = bin2str(valcontent)

end if

end if

if instrb(startpos, formdata, divider) < 1 then

exit do

end if

startpos = instrb(startpos, formdata, divider) + lenb(divider) + 2

loop

end function

function bin2str(binstr)

dim varlen, clow, ccc, skipflag

skipflag = 0

ccc = ""

varlen = lenb(binstr)

for i = 1 to varlen

if skipflag = 0 then

clow = midb(binstr, i, 1)

if ascb(clow) > 127 then

ccc = ccc & chr(ascw(midb(binstr, i + 1, 1) & clow))

skipflag = 1

else

ccc = ccc & chr(ascb(clow))

end if

else

skipflag = 0

end if

next

bin2str = ccc

end function

function str2bin(str)

for i = 1 to len(str)

str2bin = str2bin & chrb(asc(mid(str, i, 1)))

next

end function

function getfilename(str,path,savtype)

set fs = server.createobject("scripting.filesystemobject")

str = rightb(str,lenb(str)-instrb(str,str2bin("filename="))-9)

getfilename = ""

filename = ""

for i = lenb(str) to 1 step -1

if midb(str, i, 1) = chrb(asc("\")) then

filename = midb(str, i + 1, lenb(str) – i – 1)

exit for

end if

next

if savtype = 0 and fs.fileexists(path & bin2str(filename)) = true then

hfilename = filename

rfilename = ""

for i = lenb(filename) to 1 step -1

if midb(filename, i, 1) = chrb(asc(".")) then

hfilename = leftb(filename, i-1)

rfilename = rightb(filename, lenb(filename)-i+1) hfilename文件名rfilename文件后辍

exit for

end if

next

for i = 0 to 9999

hfilename = hfilename & str2bin(i)

if fs.fileexists(path & bin2str(hfilename) & i & bin2str(rfilename)) = false then

filename = hfilename & str2bin(i) & rfilename hfilename文件名rfilename文件后辍

exit for

end if

next

end if

set fs = nothing

getfilename = filename

end function

%>

赞(0)
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com 特别注意:本站所有转载文章言论不代表本站观点! 本站所提供的图片等素材,版权归原作者所有,如需使用,请与原作者联系。未经允许不得转载:IDC资讯中心 » 以下代码如何修改,才能限制上传文件类型?-ASP教程,脚本编码
分享到: 更多 (0)