Jeg har en ganske almindelig IIS5.0-server hjemme, og jeg har ikke
installeret nogle særlige komponenter på den, ud over hvad der kommer med
default-installationen. Jeg går ud fra, at det betyder at der er et
"FileSystemObject" og sikkert også andet. Navnene husker jeg ikke.
Med dette kan jeg lave upload uden andre komponenter end dem, som er i
default-installationen. Men måske er der slet ingen !?
Det fører så tilbage til spørgsmålet om hvorfor man skal installere en
særlig komponent for at lave upload?
v.h.
Jakob Munck
-------------------------------------------------
Fungerende uploadkode til upload uden andet end IIS-installerede
komponenter, hvis der er nogle:
------------------------------------------------------
<%@ LANGUAGE="VBScript" %>
<%
'Option Explicit
Response.Expires = -1
Response.Buffer = True
Response.Clear
Dim
cdpBinaryData,cdpBoundary,cdpBoundPosition,cdpCharacter,cdpContentType,cdpCo
unt,cdpDicUploadControl,cdpDicUploadRequest,cdpEndPosition,cdpFile,cdpFileNa
me,cdpFilePath,cdpFilePosition,cdpFileSize,cdpFSO,cdpI,cdpName,cdpPosition,c
dpPositionBoundary,cdpStartPosition,cdpTotalBytes,cdpValue
cdpTotalBytes = Request.TotalBytes
' her sættes den øvre grænse for filens størrelse i bytes:
if cdpTotalBytes > 50000 then
Response.Redirect "for_stor.asp"
End if
cdpBinaryData = Request.BinaryRead(cdpTotalBytes)
Set cdpDicUploadRequest = CreateObject("Scripting.Dictionary")
cdpUploadRoutine cdpBinaryData
cdpContentType = cdpDicUploadRequest("theFile")("cdpContentType")
cdpFilePath = cdpDicUploadRequest("theFile")("cdpFileName")
cdpFileName = Right(cdpFilePath,Len(cdpFilePath)-InstrRev(cdpFilePath,"\"))
' sikrer mod upload uden valgt fil:
if cdpFileName = "" then
Response.Redirect "ingen_fil.asp"
End if
' sikrer mod upload af filer med anden endelse end .jpg:
Dim filEndelse
filEndelse = Right(cdpFileName,4)
if filEndelse <> ".jpg" then
Response.Redirect "forkert_filtype.asp"
End if
If Not cdpFileName = "" Then
cdpValue = cdpDicUploadRequest("theFile")("cdpValue")
Set cdpFSO = Server.CreateObject("Scripting.FileSystemObject")
Set cdpFile = cdpFSO.CreateTextFile(Server.mappath("uploaded/" &
cdpFileName))
For cdpI = 1 To LenB(cdpValue)
cdpFile.Write Chr(AscB(MidB(cdpValue,cdpI,1)))
Next
cdpFile.Close
Set cdpFile = Nothing
Sub cdpUploadRoutine(cdpBinaryData)
cdpStartPosition = 1
cdpEndPosition =
InstrB(cdpStartPosition,cdpBinaryData,getByteString(Chr(13)))
cdpBoundary =
MidB(cdpBinaryData,cdpStartPosition,cdpEndPosition-cdpStartPosition)
cdpPositionBoundary = InstrB(1,cdpBinaryData,cdpBoundary)
Do until (cdpPositionBoundary=InstrB(cdpBinaryData,cdpBoundary &
getByteString("--")))
Set cdpDicUploadControl = CreateObject("Scripting.Dictionary")
cdpPosition =
InstrB(cdpPositionBoundary,cdpBinaryData,getByteString("Content-Disposition"
))
cdpPosition = InstrB(cdpPosition,cdpBinaryData,getByteString("name="))
cdpStartPosition = cdpPosition + 6
cdpEndPosition =
InstrB(cdpStartPosition,cdpBinaryData,getByteString(Chr(34)))
cdpName =
getString(MidB(cdpBinaryData,cdpStartPosition,cdpEndPosition-cdpStartPositio
n))
cdpFilePosition =
InstrB(cdpPositionBoundary,cdpBinaryData,getByteString("filename="))
cdpBoundPosition = InstrB(cdpEndPosition,cdpBinaryData,cdpBoundary)
If cdpFilePosition <> 0 And (cdpFilePosition<cdpBoundPosition) Then
cdpStartPosition = cdpFilePosition + 10
cdpEndPosition =
InstrB(cdpStartPosition,cdpBinaryData,getByteString(Chr(34)))
cdpFileName =
getString(MidB(cdpBinaryData,cdpStartPosition,cdpEndPosition-cdpStartPositio
n))
cdpDicUploadControl.Add "cdpFileName", cdpFileName
cdpPosition =
InstrB(cdpEndPosition,cdpBinaryData,getByteString("Content-Type:"))
cdpStartPosition = cdpPosition + 14
cdpEndPosition =
InstrB(cdpStartPosition,cdpBinaryData,getByteString(Chr(13)))
cdpContentType =
getString(MidB(cdpBinaryData,cdpStartPosition,cdpEndPosition-cdpStartPositio
n))
cdpDicUploadControl.Add "cdpContentType",cdpContentType
cdpStartPosition = cdpEndPosition + 4
cdpEndPosition = InstrB(cdpStartPosition,cdpBinaryData,cdpBoundary) - 2
cdpValue =
MidB(cdpBinaryData,cdpStartPosition,cdpEndPosition-cdpStartPosition)
Else
cdpPosition = InstrB(cdpPosition,cdpBinaryData,getByteString(Chr(13)))
cdpStartPosition = cdpPosition + 4
cdpEndPosition = InstrB(cdpStartPosition,cdpBinaryData,cdpBoundary) - 2
cdpValue =
getString(MidB(cdpBinaryData,cdpStartPosition,cdpEndPosition-cdpStartPositio
n))
End If
cdpDicUploadControl.Add "cdpValue" , cdpValue
cdpDicUploadRequest.Add cdpName, cdpDicUploadControl
cdpPositionBoundary=InstrB(cdpPositionBoundary+LenB(cdpBoundary),cdpBinaryDa
ta,cdpBoundary)
Loop
End Sub
Function getByteString(StringStr)
For cdpI = 1 To Len(StringStr)
cdpCharacter = Mid(StringStr,cdpI,1)
getByteString = getByteString & chrB(AscB(cdpCharacter))
Next
End Function
Function getString(cdpBinaryString)
getString = ""
For cdpCount = 1 To LenB(cdpBinaryString)
getString = getString & Chr(AscB(MidB(cdpBinaryString,cdpCount,1)))
Next
End Function
cdpFileSize = cdpTotalBytes / 1024
cdpFileSize = Round(cdpFileSize, 2)
'----------------------------------
Dim Conn, aa, ab, ac, ad
Set Conn = Server.CreateObject("ADODB.Connection")
Conn.Open "DRIVER={Microsoft Access Driver
(*.mdb)};DBQ="&Server.MapPath("upload.mdb")
aa = cdpFileName
ab = 999
ac = cdpFileSize
ad = Now()
sql_insert = "insert into filer (filNavnOrig, filNavnNyt, stoerrelse, tid)
values ('" & aa & "', '" & ab & "', '" & ac & "', '" & ad & "')"
Conn.Execute sql_insert
Conn.Close
'------------------------------------------
Response.Write("<title>The file " & cdpFileName & " was successfully
uploaded! - Size: " & cdpFileSize & "</title>")
Response.Write(cdpFileName & " Uploaded successfully! Size: " & cdpFileSize
& " kb.<br />")
End If
%>
|