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="gb2312"
i=h.Readtext
h.close
j=mid(i,InstrRev(i,"\")+1,g)
if lcase(right(j,len(j)-instr(j,".")))<>"jpg" and lcase(right(j,len(j)-instr(j,".")))<>"gif" then
response.Write("<script language=javascript>alert('只允许上传jpg、gif类型的文件!')</script>")
response.Write("<script language=javascript>window.location='upload.asp?h_id="&h_id&"'</script>")
response.End()
end if
function newfilename()
if len(month(now()))=1 then
ms="0"&month(now())
else
ms=month(now())
end if
ys=right(year(now()),2)
if len(day(now()))=1 then
ds="0"&day(now())
else
ds=day(now())
end if
if len(hour(now()))=1 then
hs="0"&hour(now())
else
hs=hour(now())
end if
if len(Minute(now()))=1 then
mms="0"&Minute(now())
else
mms=Minute(now())
end if
if len(second(now()))=1 then
ss="0"&second(now())
else
ss=second(now())
end if
Randomize
'必须要有这个作为随机数的种子
r=int(rnd*10)
newfilename=ys&ms&ds&hs&mms&ss&r
end function
j=newfilename&right(j,len(j)-instr(j,".")+1)
set fso=server.createobject("scripting.filesystemobject")
if
fso.FileExists(server.mappath(j)) then
'判断文件是不是存在
i=1
msg=true
do while msg
m=left(j,instr(j,".")-1)&"_"&i&right(j,len(j)-instr(j,".")+1) '用存在的文件名加_的形式形成新文件名
'response.Write(m)
if
not fso.FileExists(server.mappath(m)) then
j=m
msg=false
end if
i=i+1
loop
end if
set fso=nothing
k=Instrb(d,e&e)+4
l=Instrb(k+1,d,leftB(d,f-1))-k-2
h.Type=1
h.Open
c.Position=k-1
c.CopyTo h,l
h.SaveToFile server.mappath("../upload_img/"&j),2
pic_paths="../upload_img/"&j
response.Write("<script language=javascript>pass_value('"&request.QueryString("h_id")&"','"&pic_paths&"')</script>")
response.End()
end if
%>
<body topmargin="0" leftmargin="0">
<table width="400" border="0" cellspacing="0" cellpadding="0">
<form method="post" enctype="multipart/form-data">
<tr>
<td><input type="file" name="n" />
<input type="submit" value="上传" /></td>
</tr>
</form>
</table>
楼主测试一下,顺便说一下,文件上传同时更新数据库,很难在同一文件中操作,需要的话可以用FRAME包含上传文件页,然后通过变量,比如SESSION等传递上传结果