.:thomas:.: Fileupload in DB

Beitrag lesen

Hallo,
ich habe ein Script gefunden, mir dem man Files in eine Access-DB laden kann. Funktioniert auch soweit.

Jetzt habe ich nur eine doofe Frage :-),
Wie kann ich diese Dateien anzeigen lassen und wieder auslesen?

Danke.

PS. Ich häng mal das Script mit ran, vielleicht machst sich ja jemand die Mühe, es mal anzuschauen.

<%Option Explicit%>
<!--#INCLUDE FILE="upload.inc"-->
<!--#INCLUDE FILE="format.inc"-->
<%
  UploadSizeLimit = 1000000
  response.write Head("News editieren", "")
  response.write dbDescription
  response.write CheckRequirements
%>

<Table>
  <form method=post ENCTYPE="multipart/form-data">
    <TR><TD><font face="Arial" size="2">Mail von:</font></TD><TD><font face="Arial" size="2"><input size="60" name="Mail"></font></TD></TR>
  <tr>
    <TD valign="top"><font face="Arial" size="2">Meldung:</font></TD><TD><font face="Arial" size="2"><textarea cols="60" rows="8" name="Meldung"></textarea></font></TD>
  </tr>
  <tr>
    <TD><font face="Arial" size="2">Symbol:</font></TD><TD><font face="Arial" size="2"><input type="radio" value="V2" name="R1" checked>Excel<br>
      <input type="radio" value="V3" name="R1">PDF<br>
      <input type="radio" value="V4" name="R1">Winword</font></TD>
  </tr>
  <tr>
    <TD><font face="Arial" size="2">Datei:</font></TD><TD><font face="Arial" size="2"><input type="file" size="40" name="DBFile"></font></TD>
  </tr>
    <TR><TD></TD><TD><font face="Arial" size="2"><input type="submit" Name="Action" value="Datei auf den Server laden"></font></TD></TR>
  </form>
</Table>

<%=Foot%>

<SCRIPT RUNAT=SERVER LANGUAGE=VBSCRIPT>
'Some value greater than default of 60s (According to upload size.)
'The maximum speed is about 100kB/s for IIS4, P200 and local upload, 4kB/s for modem users.
Server.ScriptTimeout = 200

If Request.ServerVariables("REQUEST_METHOD") = "POST" Then 'Request method must be "POST" for get the fields
  '*************************************************   Main Upload - start
    Dim Fields
    'on error resume next
    'Gets uploaded fields
    Set Fields = GetUpload()
    'There are all of form fields in the Fields object. Example :
    'Fields("File1").ContentType - content type of File1 field
    'Fields("File1").Value.String - File1 field converted to a string
    'Fields("File1").Value.ByteArray - File1 field as safearray to store in binary RS field or file
    'Fields("Comments").Value.String - value of Comments field

If Err = 0 Then 'Upload was OK
      'Saves fields to the database and returns result to the client.
      Response.Write DBSaveUpload(Fields)
    Else 'Error in upload. Write the error
      Response.Write Err.Description
    End If
    On Error GoTo 0
    Fields = Empty 'Clear the variable
  '*************************************************   Main Upload - end
End If 'Request method must be "POST"

function DBSaveUpload(Fields)
  dim Conn, RS
  Set Conn = GetConnection
  Set RS = Server.CreateObject("ADODB.Recordset")
  RS.Open "Upload", Conn, 2, 2
  RS.AddNew
    RS("UploadDT") = Now()

RS("RemoteIP") = Request.ServerVariables("REMOTE_ADDR")
    RS("ContentType") = Fields("DBFile").ContentType
    RS("SourceFileName") = Fields("DBFile").FileName
    RS("DataSize") = Fields("DBFile").Value.Length

RS("Meldung") = Fields("Meldung").Value.String
    RS("Mail") = Fields("Mail").Value.String
    if IncludeType=1 then
      RS("Data").AppendChunk Fields("DBFile").Value.ByteArray
    Else'For PureASP upload - String is implemented as method.
      RS("Data").AppendChunk MultiByteToBinary(Fields("DBFile").Value.ByteArray)
    End If

RS.Update
  RS.Close
  Conn.Close
  DBSaveUpload = "<font face='Arial' size='2'><br>Datei <b>" & Fields("DBFile").FileName & "</b>, Grösse: <b>" & Fields("DBFile").Length & " Byte</b> in der Datenbank gespeichert! "
end function

Function MultiByteToBinary(MultiByte)
  Dim RS, LMultiByte, Binary
  Const adLongVarBinary = 205
  Set RS = CreateObject("ADODB.Recordset")
  LMultiByte = LenB(MultiByte)
  RS.Fields.Append "mBinary", adLongVarBinary, LMultiByte
  RS.Open
  RS.AddNew
    RS("mBinary").AppendChunk MultiByte & ChrB(0)
  RS.Update
  Binary = RS("mBinary").GetChunk(LMultiByte)
  MultiByteToBinary = Binary
End Function

function GetConnection()
  dim Conn, AuthConnectionString
  Set Conn = Server.CreateObject("ADODB.Connection")
  AuthConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath("upload.mdb")
  Conn.open AuthConnectionString
  set GetConnection = Conn
end function
</SCRIPT>