**********************************
<%@ Language=VBScript %>
<% Option Explicit %>
<HTML>
<HEAD>
<TITLE>SoftArtisans FileUp File And Form Upload Sample</TITLE>
</HEAD>
<BODY>
<%
'-----------------------------------------------------------------------
'--- FileUp File And Form Upload Sample
'---
'--- This sample demonstrates how to perform a single file upload
'--- with FileUp, and display many properties of the file to the user
'--- This is the ASP form-response script that uses FileUp to receive and
'--- process the upload submitted from form.asp
'--- Copyright (c) 2002 SoftArtisans, Inc.
'--- Mail: info@softartisans.com
http://www.softartisans.com'-----------------------------------------------------------------------
'--- Declarations
Dim oFileUp
Dim i
Dim subitem
'--- Instantiate the FileUp object
Set oFileUp = Server.CreateObject("SoftArtisans.FileUp")
'--- Set the Path property to the location you wish to
'--- temporarily cache the incoming file before saving
'--- Note: This property must be set immediately after
'--- instantiating the FileUp object
oFileUp.Path = Server.MapPath(Application("vroot") & "/temp")
'--- First, we'll handle the file
'--- Check to be sure there was a file selected in the form
'--- If so, continue processing
If Not oFileUp.Form("myFile").IsEmpty Then
'--- Save the file
'--- Note: The Save() method saves the file
'--- with its original name to the directory
'--- you set as the Path property.
'--- To save a file to a different location
'--- or with a different name, use the SaveAs() method
'--- instead of Save()
oFileUp.Form("myFile").Save
'--- The file is saved, display a confirmation message
Response.Write("<DIV ALIGN=center><B>File saved successfully on the server.</B></DIV>")
Response.Write("<HR NOSHADE>")
'--- Display file information in a HTML table
Response.Write("<TABLE BORDER=1 ALIGN=center CELLSPACING=1 CELLPADDING=1>")
'--- The ServerName property is the full path of the file as it was
'--- saved on the server
Response.Write("<TR><TD><B>File path on server</B></TD>")
Response.Write("<TD>" & oFileUp.Form("myFile").ServerName & "</TD></TR>")
'--- UserFileName is the full path of the file from the client's computer
Response.Write("<TR><TD><B>Original file path</B></TD>")
Response.Write("<TD>" & oFileUp.Form("myFile").UserFileName & "</TD></TR>")
'--- ShortFileName is the original file name
Response.Write("<TR><TD><B>Original file name</B></TD>")
Response.Write("<TD>" & oFileUp.Form("myFile").ShortFileName & "</TD></TR>")
'--- TotalBytes is the total byte size of the file
Response.Write("<TR><TD><B>Byte size of file</B></TD>")
Response.Write("<TD>" & oFileUp.Form("myFile").TotalBytes & "</TD></TR>")
Response.Write("</TABLE>")
'--- Pasting to the Access database...
Set objConn = Server.CreateObject("ADODB.Connection")
objConn.Open "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=c:\sti\til\database\db.mdb;"
strSQL = "INSERT INTO tblFiler (Filnavn, Filstorrelse) VALUES ('" & oFileUp.Form("myFile").ShortFileName & "', '" & oFileUp.Form("myFile").TotalBytes & "')"
objConn.Execute(strSQL)
Else
'--- If there was no file submitted, just show a message
Response.Write("Error: There was no file submitted for upload.")
End If
'--- Display the contents of the rest of the form elements
Response.Write("<DIV ALIGN=center><H3>Non-file form elements</H3>")
'--- The following four form elements are single-selections
'--- There an only be one value selected per form item
'--- Display file information in a HTML table
Response.Write("<TABLE BORDER=1 ALIGN=center CELLSPACING=1 CELLPADDING=1>")
'--- Text Box
Response.Write("<TR><TD><B>Text box</B></TD><TD>" & oFileUp.Form("TextBox") & "</TD></TR>")
'--- Password Box
Response.Write("<TR><TD><B>Password</B></TD><TD>" & oFileUp.Form("PasswordBox") & "</TD></TR>")
'--- Radio button
Response.Write("<TR><TD><B>Radio Button</B></TD><TD>" & oFileUp.Form("RadioBtn") & "</TD></TR>")
'--- Drop-Down
Response.Write("<TR><TD><B>DropDown Listbox</B></TD><TD>" & oFileUp.Form("DropDown") & "</TD></TR>")
'--- The following two form elements are "subcollections"
'--- Multiple values can be selected in the checkbox bank and the multi-select box
'--- To access the values of subcollections, use the FormEx collection instead of Form
'--- Iterate through subcollections using a ForEach loop like this
Response.Write("<TR><TD><B>CheckBoxes</B></TD><TD>")
For Each subitem In oFileUp.FormEx("CheckBox")
Response.Write(subitem & "<BR>")
Next
Response.Write("</TD></TR>")
'--- Or a For loop like this
Response.Write("<TR><TD><B>MultiSelect</B></TD><TD>")
For i = 1 To oFileUp.FormEx("MultiSelect").Count
Response.Write(oFileUp.FormEx("MultiSelect")(i) & "<BR>")
Next
Response.Write("</TD></TR>")
Response.Write("</TABLE></DIV>")
'--- Destroy objects
Set oFileUp = Nothing
%>
</BODY>
</HTML>
Husk at lav stien om så den passer til der hvor du har placeret databasen!
//>Rune