upload.asp
<form action=http://<%= Request. ServerVariables(SERVER_NAME)>/wdread.asp method=post>
<p>主題: <input type=text name=subject><br>
作者:<input name=author type=text><br>
發布時間: <input name=date1 type=text><br>
上載文件:<input type=file name=filename>
發往URL: <input type=hidden name=TargetURL value=http://<%= Request.ServerVariables(SERVER_NAME)%>/users/<%=Request.ServerVariables(LOGON_USER) %> size=20><br>
<input type=submit value=確定> </p>
</form>
wdread.asp
<form enctype=multipart/form-data action=http://<%= Request.ServerVariables (SERVER_NAME) %>/scripts/cpshost.dll?PUBLISH?wdwriter.asp method=post name=form1>
上載文件:<input type=file name=filename value=<%=session(filename)%>>
<input type=hidden name=TargetURL value=http://<%= Request.ServerVariables (SERVER_NAME) %>/users/wdls >
<input type=button name=upload value=確定>
</form>
<scripts language=VBScript>
' 在上載時應對表單域filename的值與upload.asp程序中的域值進行比較, 因為在upload.asp中輸入的文件名在本程序中預置給表單域filename,一旦客戶端重新輸入新的文件名後提交確認,會使程序wdwriter.asp中寫入數據庫的文件名與實際上載的文件名不一樣, 導致網頁連接出錯.此處進行判斷,如果兩者相等,則立即上載,否則取消操作.
<!--
sub upload_onclick()
set myform=window.document.form1
tmp=myform.filename.value
if strcomp(tmp,<%=session
(filename)%>)=0 then
form1.submit
else
msgbox 噢,您輸入的文件名有誤,請重新輸入!
end if
end sub
-->
</scripts>
wdwriter.asp
<%
Set mydata = Server.CreateObject (ADODB.Connection) mydata.Open DSN=xczh;UID=sa;PWD=;
' 打開數據庫.
date1=session(date1)
' 取各表單域的值.取時間.
subject=session(subject)
' 取文件主題.
author=session(subject)
' 取作者.
filename=session(filename)
' 取文件名.
TargetURL= session(TargetURL)
' 取文件在服務器中存放的物理地址.
sqlstr=insert into wdlsb values( & sn & ,& subject & ', & date1 & ',&filename & ', & TargetURL &', & author & ')
' 寫數據庫並保存.
Mydata.Execute(sqlstr)
%>
[1]