新聞中心
隨著互聯(lián)網(wǎng)技術(shù)的不斷發(fā)展,文件上傳功能在網(wǎng)站開發(fā)中的使用越來越廣泛。作為網(wǎng)站開發(fā)人員,如何實(shí)現(xiàn)一個帶數(shù)據(jù)庫的文件上傳功能已成為我們需要掌握的技能之一。本文將講解如何使用功能。

創(chuàng)新互聯(lián)專業(yè)為企業(yè)提供寧縣網(wǎng)站建設(shè)、寧縣做網(wǎng)站、寧縣網(wǎng)站設(shè)計(jì)、寧縣網(wǎng)站制作等企業(yè)網(wǎng)站建設(shè)、網(wǎng)頁設(shè)計(jì)與制作、寧縣企業(yè)網(wǎng)站模板建站服務(wù),十年寧縣做網(wǎng)站經(jīng)驗(yàn),不只是建網(wǎng)站,更提供有價(jià)值的思路和整體網(wǎng)絡(luò)服務(wù)。
ASP簡介
ASP(Active Server Pages)是一種動態(tài)的網(wǎng)頁開發(fā)技術(shù),它可以方便地將HTML和Script代碼結(jié)合在一起進(jìn)行Web應(yīng)用程序的開發(fā)。ASP最初由微軟公司開發(fā),目前已經(jīng)成為了一種非常流行的腳本語言,廣泛應(yīng)用于Web應(yīng)用程序的開發(fā)中。
文件上傳功能介紹
在Web應(yīng)用程序中,文件上傳是一種常見的功能。通過文件上傳,用戶可以將本地文件上傳到服務(wù)器,從而實(shí)現(xiàn)分享、備份、下載等操作。常見的文件上傳格式有圖片、音頻、視頻、文檔等,通過文件上傳功能,可以方便地將多種文件上傳到網(wǎng)站中。
數(shù)據(jù)庫介紹
數(shù)據(jù)庫是指按照一定規(guī)則組織起來的數(shù)據(jù)的。在Web應(yīng)用程序中,數(shù)據(jù)庫可以用來存儲用戶信息、訂單信息、商品信息等數(shù)據(jù)。數(shù)據(jù)庫可以讓應(yīng)用程序?qū)崿F(xiàn)數(shù)據(jù)的持久化存儲,使得數(shù)據(jù)在多個應(yīng)用程序之間能夠共享和使用。
如何實(shí)現(xiàn)帶數(shù)據(jù)庫的文件上傳
在ASP中,通過使用FileSystemObject對象和ADODB.Recordset對象,可以很方便地實(shí)現(xiàn)文件上傳和數(shù)據(jù)庫操作。下面將簡單介紹的步驟。
一、創(chuàng)建一個ASP頁面
在Web應(yīng)用程序中,創(chuàng)建一個ASP頁面(例如:upload.asp),用于上傳文件。
二、創(chuàng)建上傳表單
在ASP頁面中,使用HTML form標(biāo)簽,創(chuàng)建文件上傳表單,并設(shè)置enctype屬性為multipart/form-data。
“`html
“`
三、接受上傳的文件
在ASP頁面中,使用FileSystemObject對象,獲取上傳的文件,并將文件保存到服務(wù)器的指定目錄中。
“`ASP
Dim objFSO, objFile
Set objFSO = Server.CreateObject(“Scripting.FileSystemObject”)
Set objFile = objFSO.GetFile(Request.Files(“fileToUpload”).Item(“FileName”))
objFile.SaveAs “d:\uploads\” & objFile.Name
Set objFile = Nothing
Set objFSO = Nothing
“`
四、保存文件信息到數(shù)據(jù)庫
在ASP頁面中,使用ADODB.Recordset對象,將上傳的文件信息保存到數(shù)據(jù)庫中。
“`ASP
Dim Conn, rs
Dim strSql
Set Conn = Server.CreateObject(“ADODB.Connection”)
Conn.Open “Provider=Microsoft.Jet.OLEDB.4.0;Data Source=” & Server.MapPath(“database\db.mdb”)
Set rs = Server.CreateObject(“ADODB.Recordset”)
strSql = “INSERT INTO upload (filename,filesize,uploadtime) VALUES (‘” & objFile.Name & “‘,'” & objFile.size & “‘,'” & Now() & “‘)”
rs.Open strSql, Conn
rs.Close
Set rs = Nothing
Conn.Close
Set Conn = Nothing
“`
五、完整的ASP頁面代碼
“`ASP
<%
Dim Conn, rs
Dim strSql
Dim objFSO, objFile
Set objFSO = Server.CreateObject(“Scripting.FileSystemObject”)
Set objFile = objFSO.GetFile(Request.Files(“fileToUpload”).Item(“FileName”))
objFile.SaveAs “d:\uploads\” & objFile.Name
Set objFile = Nothing
Set objFSO = Nothing
Set Conn = Server.CreateObject(“ADODB.Connection”)
Conn.Open “Provider=Microsoft.Jet.OLEDB.4.0;Data Source=” & Server.MapPath(“database\db.mdb”)
Set rs = Server.CreateObject(“ADODB.Recordset”)
strSql = “INSERT INTO upload (filename,filesize,uploadtime) VALUES (‘” & objFile.Name & “‘,'” & objFile.size & “‘,'” & Now() & “‘)”
rs.Open strSql, Conn
rs.Close
Set rs = Nothing
Conn.Close
Set Conn = Nothing
Response.Redirect “upload_success.asp”
%>
“`
六、
通過本文的介紹,我們了解了如何使用功能。在實(shí)際開發(fā)中,我們需要根據(jù)具體需求,進(jìn)一步完善文件上傳功能,以便滿足不同用戶的需求。同時,我們也需要注意文件上傳安全性問題,防止文件上傳功能被濫用。
成都網(wǎng)站建設(shè)公司-創(chuàng)新互聯(lián)為您提供網(wǎng)站建設(shè)、網(wǎng)站制作、網(wǎng)頁設(shè)計(jì)及定制高端網(wǎng)站建設(shè)服務(wù)!
ASP網(wǎng)站的數(shù)據(jù)庫上傳到服務(wù)器的路徑怎么設(shè)置?
網(wǎng)站根目錄找到conn這個文件
用記事明耐橋本畝缺打開
直接修改激猛里面的就可以了
不會在咨詢我
/KS_Data/KesionCMS6.mdb/表示站點(diǎn)的根目錄,也就是你存放站點(diǎn)首頁的目錄。在根目錄下建立一個KS_Data的目錄,把數(shù)據(jù)庫放到這個目錄就行了。當(dāng)然你也可以建立其它名稱的目埋型錄來存放數(shù)據(jù)。如:/Database/myData.mdb還可以將數(shù)據(jù)庫放在wwwroot主目錄的上彎鬧猜級目錄,這樣只有程序能訪問到數(shù)據(jù)庫彎哪,從客戶端是訪問不到的。
asp功能模塊里將上傳文件文件名和路徑導(dǎo)入數(shù)據(jù)庫
我剛改寫了一個函數(shù)uploadfile(filety,savepath)
之一個參數(shù)是允許的后綴名第二個參數(shù)是保存地址
能夠自動防止重名,返回值是新文件名。把新文件名寫到數(shù)據(jù)庫就行啦。
0 Then
formsize=request.totalbytes’ 取二進(jìn)制流字節(jié)長度
formdata=request.binaryread(formsize)’ 讀取二進(jìn)制流內(nèi)容
bncrlf=chrB(13)&chrB(10)
datastart=instrb(formdata,bncrlf&bncrlf)+’ 取二進(jìn)制流文件開始位置 (兩個回車換行符)
divider=leftB(formdata,instrb(formdata,bncrlf)-1) ‘ 定義取二進(jìn)制流 Field 分隔標(biāo)記 (內(nèi)容為二進(jìn)制)
dataend=instrb(datastart,formdata,divider)-datastart ‘ 取二進(jìn)制流文件部分結(jié)束位置
‘2.將獲取的信息以二進(jìn)制流文件存放 — stm
Set strm=createObject(“adodb.stream”)
with strm
.type=’ 二進(jìn)制模式
.mode=’ 指定打開模式為讀寫
.open
.write formdata’寫入二臘液跡進(jìn)制流內(nèi)容
.position=’將游標(biāo)指向數(shù)據(jù)首部
.type=’ 以文本模式讀取
.CharSet = “gb2312” ‘設(shè)置中文編碼
formhead=.ReadText(datastart- 1) ‘讀取表單頭部內(nèi)容
End with
‘2.1獲取上傳的文件名稱filename
fullname=fRegExpSgl(formhead,true,true,true,”*filename\=””(.*?)””*”,”$1″)
fname=Split(fullname,”\”)
filename=fname(UBound(fname)) ‘ 獲取到文件名
‘判斷文件類型是否輪并安全
filety=split(filety,”,”)’轉(zhuǎn)化成數(shù)組
for i=0 to ubound(filety)
if lcase(right(filename,3))=lcase(filety(i)) then ‘right
exit for
else
end if
next
‘end 判斷文件類型
Set fso = Server.CreateObject(“Scripting.FileSystemObject”)
If fso.FileExists(savepath&filename) Then
For i=1 To 999
Fxname=Split(filename,”.”)
Fn=Left(filename,InstrRev(filename,”.”)-1)
Fnx=fxname(UBound(fxname))
If Not fso.FileExists(SavePath&Fn&”(“&i&”).”&Fnx) Then
filename=Fn&”(“&i&”).”&Fnx
Exit For
End If
Next
End If
‘3.從stm二進(jìn)制流文件中獲取有效信息 及 保存文件
Set formstrm=createOBject(“adodb.stream”)
with formstrm
.type=’ 二進(jìn)制模式
.mode=3
.open
strm.position = datastart ‘ 指定 stm 對象的起始位置, 以變量 bStart 的值為起始位置
strm.copyTo formstrm,dataend ‘ 拷貝 stm 二進(jìn)制流至 fromStm 對象, 長度為 bEnd 變量的長度
.saveTofile (savepath&filename),2 ‘ 保存文件, 如果存在相同名稱, 則覆蓋
.close
end with
Set strm=Nothing
Set formstrm=Nothing
‘dele the old photo and write the position to the user table faceurl
‘findout the old photo
upload=filename
‘response.End 這個導(dǎo)致下面的所有的將輸出不了
End If
‘end upload****************
end function
function fRegExpSgl(str,glb,igc,mtl,pt,rpt)
dim re
set re=new RegExp
re.global=glb
re.ignoreCase=igc
re.multiline=mtl
re.pattern=pt
fRegExpSgl=re.replace(str,rpt)
set re=nothing
end function
關(guān)于asp上傳帶數(shù)據(jù)庫的介紹到此就結(jié)束了,不知道你從中找到你需要的信息了嗎 ?如果你還想了解更多這方面的信息,記得收藏關(guān)注本站。
香港云服務(wù)器機(jī)房,創(chuàng)新互聯(lián)(www.cdcxhl.com)專業(yè)云服務(wù)器廠商,回大陸優(yōu)化帶寬,安全/穩(wěn)定/低延遲.創(chuàng)新互聯(lián)助力企業(yè)出海業(yè)務(wù),提供一站式解決方案。香港服務(wù)器-免備案低延遲-雙向CN2+BGP極速互訪!
分享文章:ASP實(shí)現(xiàn)帶數(shù)據(jù)庫的文件上傳(asp上傳帶數(shù)據(jù)庫)
本文網(wǎng)址:http://m.fisionsoft.com.cn/article/cohpcos.html


咨詢
建站咨詢
