Upload af filer med Aspsmartupload
Jeg har prøvet at lave et uploadscript som skal uploade nogle filer til serveren, samt tilføje noget tekst til min database og filnavn på de 2 filer jeg uploader til databasen.Det går galt og jeg får følgende:
Item cannot be found in the collection corresponding to the requested name or ordinal.
/u/1upload.asp, line 58
1upload.asp, line 58
oRs.AddNew
----> file.FileToField oRs.Fields("FILE")
oRs("filnavn") = file1.FileName
oRs("picnavn") = file2.FileName
Nogen der kan hjælpe?
Det er nok fordi jeg skal have flere filer uploaded (2 stk.) og der har jeg ikke helt haft styr på når det er flere.
Her er min kode:
upload.htm:
<HTML>
<BODY BGCOLOR="white">
<FORM METHOD="POST" ACTION="1upload.asp" ENCTYPE="multipart/form-data">
<table border="0" width="500" cellspacing="0" cellpadding="2" id="table1">
<tr>
<td width="100%" style="border: 1 solid #000000" bgcolor="#808080">
<p style="margin-top: 0; margin-bottom: 0">
<b><font face="verdana" size="1" color="#0000FF">Upload filmklip til
databasen:</font></b></td>
</tr>
<tr>
<td width="100%" style="border-left: 1 solid #000000; border-right: 1 solid #000000; border-bottom: 1 solid #000000" height="346">
<table border="0" width="100%" cellspacing="0" cellpadding="3" id="table2">
<tr>
<td width="11%" valign="top">
<p style="margin-top: 0; margin-bottom: 0"><b>
<font face="verdana" size="1">Overskrift</font></b></td>
<td width="87%" valign="top">
<p style="margin-top: 0; margin-bottom: 0"><font face="verdana" size="1">
<input type="text" name="overskrift" size="62" style="font-size: 8pt; font-family: Verdana; border: 1 solid #000000"></font></td>
</tr>
<tr>
<td width="11%" valign="top">
<p style="margin-top: 0; margin-bottom: 0"><b>
<font face="verdana" size="1">Beskrivelse</font></b></td>
<td width="87%" valign="top">
<p style="margin-top: 0; margin-bottom: 0">
<textarea rows="16" name="beskrivelse" cols="61" style="font-size: 8pt; font-family: Verdana; border: 1 solid #000000"></textarea></td>
</tr>
<tr>
<td width="11%" valign="top">
<p style="margin-top: 0; margin-bottom: 0"><b>
<font face="verdana" size="1">Upload<br>
Billede</font></b></td>
<td width="87%" valign="top">
<table id="table4">
<tr>
<td width="25">
<p style="margin-top: 0; margin-bottom: 0">File: </td>
<td>
<p style="margin-top: 0; margin-bottom: 0">
<INPUT TYPE="FILE" NAME="FILE1" SIZE="50"></td>
</tr>
</table>
</td>
</tr>
<tr>
<td width="11%" valign="top">
<p style="margin-top: 0; margin-bottom: 0"><b>
<font face="verdana" size="1">Upload<br>
Filmklip</font></b></td>
<td width="87%" valign="top">
<table id="table3">
<tr>
<td width="25">
<p style="margin-top: 0; margin-bottom: 0">File: </td>
<td>
<p style="margin-top: 0; margin-bottom: 0">
<INPUT TYPE="FILE" NAME="FILE2" SIZE="50"></td>
</tr>
</table>
</td>
</tr>
<tr>
<td><div align="left"><b><font face="Verdana" size="1">Kategori</font><small><font size="1" face="Verdana">
</font></small></b></td>
<td><small><font face="Verdana">
<br>
<select name="kategori">
<option value="sjove">Sjove</option>
<option value="dyr">Dyr</option>
<option value="sport">Sport</option>
<option value="vilde">Vilde</option>
<option value="pinligt">Pinligt</option>
<option value="smerte">Smerte</option>
<option value="sygt">Sygt</option>
<option value="fulde">Fulde</option>
<option value="stupid">Stupid</option>
<option value="fede">Fede</option>
<option value="styrt">Styrt</option>
<option value="jackass">Jackass</option>
<option value="fight">Fight</option>
<option value="hygge">hygge</option>
<option value="mc">MC</option>
<option value="babes">Babes</option>
<option value="streetracing">Streetracing</option>
</select>
<br></font></small></td>
</tr>
<tr>
<td width="11%" valign="top" height="32">
<p style="margin-top: 0; margin-bottom: 0"></td>
<td width="87%" valign="top" height="32">
<p style="margin-top: 0; margin-bottom: 0"><font face="verdana" size="1">
<INPUT TYPE="submit" VALUE="Send filmklip">
</font>
</td>
</tr>
</table>
</FORM>
</td>
</tr>
</table>
1upload.asp:
<HTML>
<head>
<meta http-equiv="Content-Language" content="da">
</head>
<BODY BGCOLOR="white">
<H1>Uploading</H1>
<HR>
<%
' Variables
' *********
Dim mySmartUpload
Dim file1
Dim file2
Dim oConn
Dim oRs
Dim intCount
intCount=0
Session.LCID = 1030
' Object creation
' ***************
Set mySmartUpload = Server.CreateObject("aspSmartUpload.SmartUpload")
' Upload
' ******
mySmartUpload.Upload
intCount = mySmartUpload.Save("/aspSmartUpload/Upload")
' Connect to the DB
' *****************
Set oConn = Server.CreateObject("ADODB.Connection")
curDir = Server.MapPath("\database\storedb.mdb")
oConn.Open "DBQ="& curDir &";Driver={Microsoft Access Driver (*.mdb)};DriverId=25;FIL=MS Access;"
' Open a recordset
' ****************
strSQL = "SELECT * FROM seneste"
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("filnavn") = file1.FileName
oRs("picnavn") = file2.FileName
oRs("overskrift") = mySmartUpload.form("overskrift")
oRs("beskrivelse") = mySmartUpload.form("beskrivelse")
oRs("tid") = now()
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
%>
</BODY>
</HTML>
