求高手一段asp程序解析——急,在线等

来源:百度知道 编辑:UC知道 时间:2024/05/17 01:55:30
这是一段fso文件上传代码,在网上搜的。可以上传,但是我看了老半天也没看懂它的命名规则是什么,或者说怎么给文件重新命名的。
有高手给看看吗?谢谢了!在线等!
<%
a=Request.TotalBytes
if a>0 Then
Set c=Createobject("adodb.stream")
c.Type=1
c.Open
c.Write Request.BinaryRead(a)
c.Position=0

d=c.Read
e=chrB(13)&chrB(10)
f=Instrb(d,e)
g=Instrb(f+1,d,e)

set h=Createobject("adodb.stream")
h.Type=1
h.Open
c.Position=f+1
c.Copyto h,g-f-3
h.Position=0
h.type=2
h.CharSet="BIG5"
i=h.Readtext
h.close

j=mid(i,InstrRev(i,"\")+1,g)

if instr("jsp/asp/aspx/exe/php/html/htm/...",right(j,len(j)-instr(j,".")))>0 then
session("error")="您要上传不允许的文件"
response.redirect("error.asp")
end if

j=replace(date,"-","")&right(j,len(j)-instr(j,".")+1)

set fso=server.createobject("

你要问的是文件如何保证在服务器端不重名是吧?
就这段代码啊:
原理:循环msg=true
m=left(j,instr(j,".")-1)&"("&i&")"&right(j,len(j)-instr(j,".")+1)

这行程序变成这样的话,就容易看了:

m= left (j, instr( j, "." ) - 1 ) &_
"(" & i & ")" &_
right(j, len(j)-instr(j,".")+1)

这行就是截取路径里的“.”左部分和右部中间插入一个变量作为文件名试探,
例如:\img\my.jpg
就变成中间插入:\img\my(1).jpg
\img\my(2).jpg
\img\my(3).jpg
...

并用 if not fso.FileExists(server.mappath(m)) then
这句来判断该文件是否存在服务器上,如果存在设置msg=false作为结束循环条件并采用该命名!

do while msg
m=left(j,instr(j,".")-1)&"("&i&")"&right(j,len(j)-instr(j,".")+1)
if not fso.FileExists(server.mappath(m)) then
j=m
msg=false
end if
i=i+1
loop
end if
set fso=nothing