Upload af filnavn fra billede til access DB med aspSmartUpload
Jeg er nybegynder med asp og har er problem.Jeg kan godt uploade selve billedet til en mappe på serveren, men scriptet lægger ikke filnavnet ind i databasen.
Jeg har søgt på eksperten og på www.aspsmart.com/aspsmartupload/ men har ikke fundet en enkelt vejledning til dette.
Håber er der er noget der meget enkelt kan vise mig hvad der mangler/er galt med koden.
Her er min kode:
Virk.asp
<!--#INCLUDE file = "../admin/logincheck.asp" -->
<html>
<head>
<title>Oprettelse af emner</title>
</head>
<body background="../common/images/bg.gif">
<h3>Oprettelse af nyt emne</h3>
</body>
</html>
<HTML>
<HEAD>
<META http-equiv="Content-Type" content="text/html; charset=utf-8">
</HEAD>
<BODY BGCOLOR="white">
<H1>aspSmartUpload : Sample</H1>
<HR>
<FORM METHOD="POST" ENCTYPE="multipart/form-data" ACTION="sample.asp">
<INPUT TYPE="FILE" NAME="FILE" SIZE="50"><BR>
<INPUT TYPE="SUBMIT" VALUE="Upload">
</FORM>
</BODY>
</HTML>
Sample.asp
<HTML>
<HEAD>
<META http-equiv="Content-Type" content="text/html; charset=utf-8">
</HEAD>
<BODY BGCOLOR="white">
<H1>aspSmartUpload : Sample</H1>
<HR>
<%
' Variables
' *********
Dim mySmartUpload
Dim file
Dim intCount
intCount=0
' Object creation
' ***************
Set mySmartUpload = Server.CreateObject("aspSmartUpload.SmartUpload")
' Upload
' ******
mySmartUpload.Upload
' Select each file
' ****************
For each file In mySmartUpload.Files
' Only if the file exist
' **********************
If not file.IsMissing Then
' Save the files with his original names in a virtual path of the web server
' ****************************************************************************
file.SaveAs("/common/images/" & file.FileName)
' sample with a physical path
'file.SaveAs("c:\inetpub\wwwroot\images" & file.FileName)
'Dimension variables
Dim adoCon 'Holds the Database Connection Object
Dim rsAddcomments 'Holds the recordset for the new record to be added to the database
Dim strSQL 'Holds the SQL query for the database
'Create an ADO connection odject
Set adoCon = Server.CreateObject("ADODB.Connection")
'Set an active connection to the Connection object using a DSN-less connection
adoCon.Open "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" & Server.MapPath("\db\test.mdb")
'Set an active connection to the Connection object using DSN connection
'adoCon.Open "DSN=rent"
'Create an ADO recordset object
Set rsAddComments = Server.CreateObject("ADODB.Recordset")
'Initialise the strSQL variable with an SQL statement to query the database
strSQL = "SELECT test.* FROM test;"
'Set the cursor type we are using so we can navigate through the recordset
rsAddcomments.CursorType = 2
'Set the lock type so that the record is locked by ADO when it is updated
rsAddcomments.LockType = 3
'Open the tblComments table using the SQL query held in the strSQL varaiable
rsAddcomments.Open strSQL, adoCon
'Tell the recordset we are adding a new record to it
rsAddcomments.AddNew
'Add a new record to the recordset
rsAddcomments.Fields("file")= file.FileName
ntCount = intCount + 1
End If
' Display the number of files which could be uploaded
' ***************************************************
Response.Write("<BR>" & mySmartUpload.Files.Count & " file(r) kunne blive uploaded.<BR>")
' Display the number of files uploaded
' ************************************
Response.Write(intCount & " file(r) uploaded.<BR>")
Next
'Redirect to the below page
Response.Redirect "links.asp"
%>
</BODY>
</HTML>
