ASP triks
Hvordan laste opp filer via ASP, upload.asp:
AspMaxRequestEntityAllowed i C:\windows\system32\inetsvr\metabase.xml må økes, default grense er på 200 KB.
http://www.microsoft.com/technet/prodtechnol/WindowsServer2003/Library/IIS/a6401b5e-c902-4035-90aa-ee46c270d357.mspx?mfr=true
Skrivetettigheter og slikt må selvfølgelig også plass. Basert på kode funnet på nettet, kan ikke husk hvor...
<%
if Request.TotalBytes < 10 then
%>
upload.asp
<%
else
Dim mlngBytesReceived
Dim mbinData
Dim mstrDelimiter
Dim lobjStream
Dim lobjRs
Dim lbinBytes
Dim llngLength
Dim lbinBuffer
Dim llngStart, llngStop
Dim lfileStart, lfileStop
Dim CR, LF, CRLF, FN
Dim strFilename, t
Const adVarChar = 200
Const adLongVarBinary = 205
Const adSaveCreateOverWrite = 2
Const adTypeBinary = 1
CR = ChrB(Asc(vbCR))
LF = ChrB(Asc(vbLF))
CRLF = CR & LF
FN = ChrB(Asc("e")) & ChrB(Asc("n")) & ChrB(Asc("a")) & ChrB(Asc("m")) & ChrB(Asc("e")) & ChrB(Asc("=")) & ChrB(Asc(""""))
mlngBytesReceived = Request.TotalBytes
mbinData = Request.BinaryRead(mlngBytesReceived)
mstrDelimiter = MidB(mbinData, 1, InStrB(1, mbinData, CRLF) - 1)
lfileStart = InStrB(1, mbinData, FN) + 7
lfileStop = InStrB(lfileStart, mbinData, CRLF) - 2
for t = lfileStart to lfileStop
strFilename = strFilename & Chr(AscB(MidB(mbinData, t, 1)))
next
if InStr(strFilename, "\") then
strFilename = Mid(strFilename, 1 + InStrRev(strFilename, "\"), Len(strFilename))
end if
if InStr(strFilename, "/") then
strFilename = Mid(strFilename, 1 + InStrRev(strFilename, "/"), Len(strFilename))
end if
llngStart = InStrB(1, mbinData, CRLF & CRLF) + 4
llngStop = InStrB(llngStart, mbinData, mstrDelimiter) - 2
llngLength = llngStop - llngStart
Set lobjStream = Server.CreateObject("ADODB.Stream")
lobjStream.Type = adTypeBinary
Call lobjStream.Open()
Set lobjRs = Server.CreateObject("ADODB.Recordset")
Call lobjRs.Fields.Append("BinaryData", adLongVarBinary, llngLength)
Call lobjRs.Open()
Call lobjRs.AddNew()
Call lobjRs.Fields("BinaryData").AppendChunk(MidB(mbinData, llngStart, llngLength + 1))
Call lobjRs.Update()
lbinBuffer = lobjRs.Fields("BinaryData").GetChunk(llngLength)
Call lobjStream.Write(lbinBuffer)
Call lobjStream.SaveToFile("C:\inetpub\offline\files\" & strFilename, adSaveCreateOverWrite)
Call lobjRs.Close()
Set lobjRs = Nothing
Call lobjStream.Close()
Set lobjStream = Nothing
Response.Write llngLength & "" & strFilename
end if
%>