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]