Jag har kollat på hemsida för ASPupload och satt ihop detta. Den uppladdade filen sparas i mappen "uploaded". Problemet är att jag vill spara allt i en databas, (namn, extra, fil, filstorlek). Hur gör jag detta? Istället för: om jag förstår dig rätt så vill du spara filen och övrig info i DB:n?ASPupload till databas
<code>
<%
Set Upload = Server.CreateObject("Persits.Upload.1")
Upload.OverwriteFiles = False
On Error Resume Next
Upload.SetMaxSize 1048576 ' Limit files to 1MB
Count = Upload.SaveVirtual (".\uploaded")
%>
<HTML>
<BODY BGCOLOR="#FFFFFF">
<CENTER>
<% If Err <> 0 Then %>
<H3>The following error occured while uploading:</h3>
<h2>"<% = Err.Description %>"</h2>
<% Else %>
<h2>Success! <% = Count %> file(s) have been uploaded.</h2>
<TABLE BORDER=1 CELLPADDING=3 CELLSPACING=0>
<TD><B>Image:</B></TD>
<% If Count > 0 Then %>
<%
Set File = Upload.Files(1)
If Not File Is Nothing Then
' Build ODBC connection string
Connect = "Driver={Microsoft Access Driver (*.mdb)};DBQ=" & Server.MapPath(".\db\databas.mdb")
' Build SQL INSERT statement
SQL = "INSERT INTO test(namn, extra, fil) VALUES(?, '"
SQL = SQL & File.Filename & "', '"
SQL = SQL & Replace(Upload.Form("DESCR"), "'", "''") & "', "
SQL = SQL & File.Size & ")"
' Save to database
File.ToDatabase Connect, SQL
Response.Write "File saved."
Else
Response.Write "File not selected."
End If
Else %>
<TD>File not selected.</TD>
<% End If %>
<TR>
<TD><B>Description:</B></TD><TD><% = Upload.Form("Description") %> </TD><TR>
<TD><B>Categories:</B></TD>
<TD>
<%
For Each Item in Upload.Form
If Item.Name = "Category" Then Response.Write Item.Value & "<BR>"
Next%>
</TD>
</TABLE>
<P>
Click here to upload more files.
<% End If %>
</CENTER>
</BODY>
</HTML>
</code>Sv: ASPupload till databas
<code>
SQL = "INSERT INTO test(namn, extra, fil) VALUES(?, '"
SQL = SQL & File.Filename & "', '"
SQL = SQL & Replace(Upload.Form("DESCR"), "'", "''") & "', "
SQL = SQL & File.Size & ")"</code>
Så kan du lägga in:
<code>
filnamn = File.Filename
info = Replace(Upload.Form("DESCR"), "'", "''")
storlek = File.Size
SQL="INSERT INTO test(namn, extra, fil)"
SQL = SQL & "Values('"& filnamn &"','"& info &"','"& storlek &"')"
Conn.Execute(SQL)
</code>
Det kan fungera... har inte testat det...
Testa om det funkar....Sv: ASPupload till databas
här är ett exempel klippt och klistrat ifrån aspupload.com på hur du gör:
<code>
<HTML>
<BODY>
<%
Set Upload = Server.CreateObject("Persits.Upload")
' Capture files
Upload.Save "c:\upload"
' Obtain file object
Set File = Upload.Files("THEFILE")
If Not File Is Nothing Then
' Build ODBC connection string
Connect = "Driver={Microsoft Access Driver (*.mdb)};DBQ=" & Server.MapPath(".\aspupload.mdb")
' If you use SQL Server, the connecton string must look as follows:
' Connect = "Driver=SQL Server;Server=MYSERVER;UID=sa;PWD=xxxxxxxxx"
' Build SQL INSERT statement
SQL = "INSERT INTO MYIMAGES(image_blob, filename, description, filesize) VALUES(?, '"
SQL = SQL & File.Filename & "', '"
SQL = SQL & Replace(Upload.Form("DESCR"), "'", "''") & "', "
SQL = SQL & File.Size & ")"
' Save to database
File.ToDatabase Connect, SQL
Response.Write "File saved."
Else
Response.Write "File not selected."
End If
%>
</BODY>
</HTML>
</code>
mvh
Martin