我們是利用upload檔案上傳組件進行檔案上傳哦。
<%Server.ScriptTimeOut=5000%>
<!--#include file="conn.asp"-->
<!--#include FILE="upload_5xsoft.inc"-->
<html>
<head>
<title>檔案上傳</title>
<link rel="stylesheet" href="<%=css%>" type="text/css">
<meta http-equiv="Content-Type" content="text/html; charset=gb2312"></head>
<body>
<%dim upload,file,formName,formPath,iCount,exeec,wjm
set upload=new upload_5xsoft
formPath="FJ/"
ly=upload.form("content")
yhm=upload.form("yhm")
zid=upload.form("zid")
ys=upload.form("ys")
yyzm = upload.form("yzm")
zt=upload.form("zt")
ztid=upload.form("ztid")
cz=upload.form("cz")
tp=upload.form("tp")
if tp = "http://" then tp = ""
ly=xrzh(ly)
if cz = "" then
fhlj = "bbs_list.asp?zid="&zid
else
fhlj = "bbs_tj.asp?page=1000&zt="&zt&"&ztid="&ztid&"&zid="&zid
zid = ztid
end if
if yyzm <> session(sessionvalue & "yzm") then redirect fhlj
zhhf = jdsj
if yhm = "" then yhm = "遊客"''request.servervariables("remote_addr")
for each formName in upload.objFile ''列出所有上傳了的檔案
set file = upload.file(formName)
if file.FileSize>0 then
kzm = lcase(right(file.filename,4))
if instr(",.mpg.asf.avi.mp3.swf.mpeg.png.gif.bmp.jpg.wma.wmv.txt",kzm)<= 0 then response.Redirect hflj
if file.filesize > 819200 then%>
<script language="javascript">
alert("檔案大於800k!");
window.location="<%=fhlj%>";
</script>
<%end if
wjdx = file.filesize
wjm = formpath&replace(cstr(date),"-","") & cstr(Replace(Timer(), ".", "")) & kzm
file.SaveAs Server.mappath(wjm)
dx = cstr(file.filesize/1024)
if len(dx) >6 then dx=left(dx,6)
end if
next
if trim(zt) <>"" then
sql = "select * from yrwl_tb_lt order by id desc"
set rs = server.createobject("adodb.recordset")
rs.open sql,conn,1,3
if sjk <> "" then
if rs.eof then
id = "1"
else
id = cstr(rs("id")+1)
end if
end if
rs.addnew
if sjk = "" then
if rs.eof then
id = "1"
else
id = cstr(rs("id"))
end if
end if
rs("yhm") = yhm
rs("zt") = zt
rs("ly") = ly
if wjm = "" and tp <> "" then wjm = tp
rs("fj") = wjm
rs("dx") = dx
rs("dj") = 0
rs("zd") = "5"
rs("hf") = 0
if cz = "" then
rs("zid") = "s"
rs("zhhf") = jdsj & " "&yhm
rs("lb") = zid
else
rs("zid") = zid
sql = "select * from yrwl_tb_lt where id=" & zid
set rs1 = server.createobject("adodb.recordset")
rs1.open sql,conn,1,3
rs1("zhhf") = jdsj & " "&yhm
rs1.update
rs1.close
end if
rs("sj") = jdsj
rs.update
rs.close
if instr(yhm,".") = 0 and yhm <> "遊客" then
exec="select * from yrwl_tb_admin where yhm='"&yhm&"'"
rs.open exec,conn,3,3
cs = rs("cs")
qm = rs("qm")
if isnull(cs) then cs = 0
if cs="" then cs=0
exec="update yrwl_tb_admin set cs=" & cstr( cs + 3 ) & " where yhm='" & yhm & "'"
conn.execute exec
end if
if cz = "" then
''讀檔案
if wjm <> "" then
kzm = lcase(right(wjm,3))
if instr(wjm,"http") = 0 then wjm = "../" & wjm
xswjm = gqzh(wjm)
if len(wjm)>4 and instr(wjm,"FJ")>0 then
tpxs = xswjm & "<br>附件下載:<a href=" & wjm & " target=_blank>[" & wjm &"]</a>"
else
tpxs = xswjm
end if
if tpxs = "" or (instr(wjm,"swf")>0) then tpxs = "<iframe id=kj name=kj frameborder=0 width=100% height=500 src="&wjm&"></iframe>"
end if
set fso = Server.Createobject("Scripting.FileSystemObject")
set file=fso.opentextfile(Server.mappath("tbtb.txt"),1,False)
do while file.AtEndOfStream<>true
wjnr = wjnr & file.ReadLine() & chr(13)
loop
file.close
set file = nothing
set fso = nothing
if isnull(qm) then qm = ""
ly = replace(ly,chr(13),"<br>")
wjnr = replace(wjnr,"$ti$",zt)
wjnr = replace(wjnr,"$sj$",jdsj)
wjnr = replace(wjnr,"$zt$", kill_keyword(zt))
wjnr = replace(wjnr,"$ly$", kill_keyword(ly) & "<br>" & tpxs & "--------------------------------------<Br> 個性簽名:<a title="&qm&">"&qm&"</a>")
wjnr = replace(wjnr,"$zid$",zid)
wjnr = replace(wjnr,"$qm$",qm)
wjnr = replace(wjnr,"$ztid$",id)
if instr(yhm,".")>0 then yhm=left(yhm,instrrev(yhm,"."))&"*"
wjnr = replace(wjnr,"$fyr$",yhm)
wjnr = replace(wjnr,"$lxfs$",session(sessionvalue & "lxfs"))
''寫檔案
wj = Server.mappath( "tb/" & id & ".htm" )
set myfileobject=server.CreateObject("Scripting.FileSystemObject")
set mytextfile=myfileobject.CreateTextFile(wj)
mytextfile.WriteLine wjnr
mytextfile.close
end if
set file=nothing
set upload=nothing ''刪除此對象
end if
conn.close
response.redirect fhlj%>
</body>
</html>