<%@ Page Language="VB" Debug="true" %>
<%@ import namespace="System.Data" %>
<%@ import namespace="System.Data.oledb" %>
<html>
<script language="vbscript" runat="server">
sub uploadfile(sender as object, e as eventargs)
if fileup.postedfile.contentlength<20 then
errors.text="這麼小的檔案也要上傳,背背就可以了."
fileinfo.visible=false
exit sub
else
errors.text="檢驗正常"
fileinfo.visible=true
end if
*** 以上檢查上傳檔案大小
respace.text="0"
nowspace.text="0"
*** respace指剩餘空間,nowspace指已用空間
dim xh1 as string =user1.value
dim kl1 as string =pass1.value
*** xh1指帳號,kl1指口令
dim objconnstr as string="provider=microsoft.jet.oledb.4.0;data source="
& server.mappath("ftpspace.mdb")
*** 以上兩行在源碼中應為同一語句
dim objconn as oledbconnection = new oledbconnection(objconnstr)
dim sql1 as string="select * from userlist where xh='"+xh1+"' and kl='"+kl1+"'"
dim objrscc as oledbcommand= new oledbcommand(sql1,objconn)
objconn.open()
dim objrs as oledbdatareader = objrscc.executereader()
dim ix as integer=0
dim maxs as long
dim nows as long
while ix=0
if objrs.read() then
if objrs.item("xh")=xh1 then
if objrs.item("kl")=kl1 then
if objrs.item("checkx")=1 then
ix=ix+1
maxs=objrs.item("maxspace")
nows=objrs.item("nowspace")
end if
end if
end if
else
ix=-1
end if
end while
*** 以上判定帳號與口令是否合法
if ix<=0 then
errors.text="帳號口令錯!或使用者尚未通過認證,請等待管理員認證!"
else
if fileup.postedfile.contentlength>maxs-nows then
if fileup.postedfile.contentlength>=maxs then
errors.text="檔案長度大於賦予空間大小,不能上傳!"
else
errors.text="可用空間不足,請刪除舊檔案!"
end if
*** 以上判定使用者空間的可用性
else
dim obj4str as string="provider=microsoft.jet.oledb.4.0;
data source=" & server.mappath("filelist.mdb")
*** 以上兩行在源碼中為同一語句
dim obj4 as oledbconnection = new oledbconnection(obj4str)
dim sql10 as string="select * from files"
dim objrc1 as oledbcommand= new oledbcommand(sql10,obj4)
obj4.open()
dim objrsx as oledbdatareader = objrc1.executereader()
dim fn11 as long =0
while objrsx.read()
fn11=objrsx("filename")
end while
dim fn1 as string
fn1=cstr(fn11+1)
*** 以上為使用者上傳檔案起一個唯一的主檔案名
dim objc1str as string="provider=microsoft.jet.oledb.4.0;
data source=" & server.mappath("filelist.mdb")
*** 以上兩行在源碼中為同一語句
dim objc1 as oledbconnection = new oledbconnection(objc1str)
dim sql3 as string="insert into files(filename,fsize, xh,filescript,upday)
values("+cstr(fn1)+","+cstr(fileup.postedfile.contentlength)+",'"
+xh1+"','"+fileup.postedfile.filename+"','"+cstr(now())+"')"
*** 以上三行在源碼中為同一語句
objc1.open()
dim objrs1 as oledbcommand=new oledbcommand(sql3,objc1)
dim fn2 as string
fn2="d:/netspace/spacenet/myspace/"&cstr(fn1)&".zip"
*** 給出使用者上傳檔案的絕對路徑及完整檔案名稱
fsize.text=cstr(fileup.postedfile.contentlength)
ftype.text=fileup.postedfile.contenttype
fname.text=fileup.postedfile.filename
username.text=user1.value
fileup.postedfile.saveas(fn2)
objrs1.ExecuteNonQuery()
objrs.close
dim sql5 as string="update userlist set nowspace ="+cstr(nows+fileup.postedfile.contentlength)+
",lastaccessday='"+cstr(now())+"' where xh='"+xh1+"'"
*** 以上兩行在源碼中為同一語句
dim objrnc as oledbcommand= new oledbcommand(sql5,objconn)
objrnc.executenonquery()
respace.text=cstr(maxs-nows-fileup.postedfile.contentlength)&"位元組."
nowspace.text=cstr(nows+fileup.postedfile.contentlength)&"位元組."
本文所述的方法基於無組件技術,在檔案的安全性及個人隱私方面考慮的比較多,最適合在windows server 2003配合IIS6.0平台上使用,方法簡單安全,稍加擴充,如在userlist裡添加使用者號、組號,在files裡添加組號,即可對檔案的許可權進行設定,可方便實現檔案的網路提交、驗證、共用。配合磁碟陣列,則在資料安全方面將有質的提升。