20. november 2003 - 20:23Der er
7 kommentarer og 1 løsning
upload til database
Hej
Hvad skal jeg rette her for at få den til at gemme i en database der ligger i en folder, altså en fysisk sti ?
<% ' Variables ' ********* Dim mySmartUpload Dim file Dim oConn Dim strSQL Dim oRs Dim intCount intCount=0
' Object creation ' *************** Set mySmartUpload = Server.CreateObject("aspSmartUpload.SmartUpload")
' Upload ' ****** mySmartUpload.Upload
' Connect to the DB ' ***************** Set oConn = Server.CreateObject("ADODB.Connection") curDir = Server.MapPath("\scripts\aspSmartUpload\Sample.mdb") oConn.Open "DBQ="& curDir &";Driver={Microsoft Access Driver (*.mdb)};DriverId=25;FIL=MS Access;"
' Open a recordset ' **************** strSQL = "SELECT FILENAME,FILE FROM TFILES"
Set oRs = Server.CreateObject("ADODB.recordset") Set oRs.ActiveConnection = oConn oRs.Source = strSQL oRs.LockType = 3 oRs.Open
' Select each file ' **************** For each file In mySmartUpload.Files ' Only if the file exist ' ********************** If not file.IsMissing Then
' Add the current file in a DB field ' ********************************** oRs.AddNew file.FileToField oRs.Fields("FILE") oRs("FILENAME") = file.FileName oRs.Update intCount = intCount + 1 End If Next
' Display the number of files uploaded ' ************************************ Response.Write(intCount & " file(s) uploaded.<BR>")
' Destruction ' *********** oRs.Close oConn.Close Set oRs = Nothing Set oConn = Nothing %>
Ja jeg fandt ud af at jeg ikke kunne anvende server.MapPath til en fysisk sti, jeg er kommet lidt videre men får en fejl:
Min kode : <% ' Variables ' ********* Dim mySmartUpload Dim file Dim oConn Dim strSQL Dim oRs Dim intCount intCount=0
' Object creation ' *************** Set mySmartUpload = Server.CreateObject("aspSmartUpload.SmartUpload")
' Upload ' ****** mySmartUpload.Upload
' Connect to the DB ' ***************** Set oConn = Server.CreateObject("ADODB.Connection") curDir = ("D:\aconsult.us\www\config\datasources\ads.mdb") oConn.Open "DBQ="& curDir &";Driver={Microsoft Access Driver (*.mdb)};DriverId=25;FIL=MS Access;"
' Open a recordset ' **************** strSQL = "SELECT FILENAME,id,annoncer FROM comments"
Set oRs = Server.CreateObject("ADODB.recordset") Set oRs.ActiveConnection = oConn oRs.Source = strSQL oRs.LockType = 3 oRs.Open"SELECT id, annoncer FROM comments"
' Select each file ' **************** For each file In mySmartUpload.Files ' Only if the file exist ' ********************** If not file.IsMissing Then
' Add the current file in a DB field ' ********************************** oRs.AddNew file.FileToField oRs.Fields("annoncer") oRs("FILENAME") = file.FileName oRs.Update intCount = intCount + 1 End If Next
' Display the number of files uploaded ' ************************************ Response.Write(intCount & " file(s) uploaded.<BR>")
' Destruction ' *********** oRs.Close oConn.Close Set oRs = Nothing Set oConn = Nothing %>
Linie 63 : file.FileToField oRs.Fields("annoncer")
Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.