Avatar billede madeindk Nybegynder
22. april 2006 - 19:54 Der er 4 kommentarer og
1 løsning

Upload uden komponent - brug for så meget kode?

Hej eksperter! Jeg skal bruge bruge en funktion der kun gemmer billedet og bagefter finder bredde, højde og URL på billedet?

Jeg har kiggede på denne side: http://activedeveloper.dk/articles/128/ , men synes måske ikke jeg har brug for så meget kode?
Avatar billede mitbrugernavn Praktikant
22. april 2006 - 20:11 #1
opret en fil - uploadfile.asp - med dette


<form METHOD="Post" ENCTYPE="multipart/form-data" ACTION="outputFile.asp" id="form3" name="form3">
<input TYPE="file" NAME="blob"><br>

<input TYPE="submit" value="Upload billede" NAME="Enter">
</form>

opret en fil - upload.asp - med dette

<%
Sub BuildUploadRequest(RequestBin)
    'Get the boundary
    PosBeg = 1
    PosEnd = InstrB(PosBeg,RequestBin,getByteString(chr(13)))
    boundary = MidB(RequestBin,PosBeg,PosEnd-PosBeg)
    boundaryPos = InstrB(1,RequestBin,boundary)
    'Get all data inside the boundaries
    Do until (boundaryPos=InstrB(RequestBin,boundary & getByteString("--")))
        'Members variable of objects are put in a dictionary object
        Dim UploadControl
        Set UploadControl = CreateObject("Scripting.Dictionary")
        'Get an object name
        Pos = InstrB(BoundaryPos,RequestBin,getByteString("Content-Disposition"))
        Pos = InstrB(Pos,RequestBin,getByteString("name="))
        PosBeg = Pos+6
        PosEnd = InstrB(PosBeg,RequestBin,getByteString(chr(34)))
        Name = getString(MidB(RequestBin,PosBeg,PosEnd-PosBeg))
        PosFile = InstrB(BoundaryPos,RequestBin,getByteString("filename="))
        PosBound = InstrB(PosEnd,RequestBin,boundary)
        'Test if object is of file type
        If  PosFile<>0 AND (PosFile<PosBound) Then
            'Get Filename, content-type and content of file
            PosBeg = PosFile + 10
            PosEnd =  InstrB(PosBeg,RequestBin,getByteString(chr(34)))
            FileName = getString(MidB(RequestBin,PosBeg,PosEnd-PosBeg))
            'Add filename to dictionary object
            UploadControl.Add "FileName", FileName
            Pos = InstrB(PosEnd,RequestBin,getByteString("Content-Type:"))
            PosBeg = Pos+14
            PosEnd = InstrB(PosBeg,RequestBin,getByteString(chr(13)))
            'Add content-type to dictionary object
            ContentType = getString(MidB(RequestBin,PosBeg,PosEnd-PosBeg))
            UploadControl.Add "ContentType",ContentType
            'Get content of object
            PosBeg = PosEnd+4
            PosEnd = InstrB(PosBeg,RequestBin,boundary)-2
            Value = MidB(RequestBin,PosBeg,PosEnd-PosBeg)
            Else
            'Get content of object
            Pos = InstrB(Pos,RequestBin,getByteString(chr(13)))
            PosBeg = Pos+4
            PosEnd = InstrB(PosBeg,RequestBin,boundary)-2
            Value = getString(MidB(RequestBin,PosBeg,PosEnd-PosBeg))
        End If
        'Add content to dictionary object
    UploadControl.Add "Value" , Value   
        'Add dictionary object to main dictionary
    UploadRequest.Add name, UploadControl   
        'Loop to next object
        BoundaryPos=InstrB(BoundaryPos+LenB(boundary),RequestBin,boundary)
    Loop

End Sub

'String to byte string conversion
Function getByteString(StringStr)
For i = 1 to Len(StringStr)
    char = Mid(StringStr,i,1)
    getByteString = getByteString & chrB(AscB(char))
Next
End Function

'Byte string to string conversion
Function getString(StringBin)
getString =""
For intCount = 1 to LenB(StringBin)
    getString = getString & chr(AscB(MidB(StringBin,intCount,1)))
Next
End Function
%>

opret en fil - outputfile.asp - med dette

<%
Response.Expires=0
Response.Buffer = TRUE
Response.Clear
byteCount = Request.TotalBytes
RequestBin = Request.BinaryRead(byteCount)
Dim UploadRequest
Set UploadRequest = CreateObject("Scripting.Dictionary")
BuildUploadRequest(RequestBin)
contentType = UploadRequest.Item("blob").Item("ContentType")
filepathname = UploadRequest.Item("blob").Item("FileName")
filename = Right(filepathname,Len(filepathname)-InstrRev(filepathname,"\"))

value = UploadRequest.Item("blob").Item("Value")
Set ScriptObject = Server.CreateObject("Scripting.FileSystemObject")
Set MyFile = ScriptObject.CreateTextFile(Server.mappath("../../db/images_butik/"&filename))
For i = 1 to LenB(value)
    MyFile.Write chr(AscB(MidB(value,i,1)))
Next
MyFile.Close    %>


<!--#include file="upload.asp"-->
<%
response.write filename
%>

sådan oploader du uden komponent

højde - bredde skal du bruge asp.images komponent til
Avatar billede mitbrugernavn Praktikant
22. april 2006 - 20:12 #2
denne linie i outputfile.asp -> husk at rette stien til din billedmappe
Set MyFile = ScriptObject.CreateTextFile(Server.mappath("billedmappe/"&filename))
Avatar billede madeindk Nybegynder
22. april 2006 - 20:29 #3
upload.asp og outputfile.asp kan ikke komme ind under den samme fil?
Avatar billede madeindk Nybegynder
22. april 2006 - 20:40 #4
Nej, det er ligemeget. Det fungerer fint :-)

Jeg læste lige scriptet ordentligt igennem.

Har givet point.
Avatar billede mitbrugernavn Praktikant
22. april 2006 - 20:59 #5
takker - og god aften
Avatar billede Ny bruger Nybegynder

Din løsning...

Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.

Loading billede Opret Preview
Kategori
Kurser inden for grundlæggende programmering

Log ind eller opret profil

Hov!

For at kunne deltage på Computerworld Eksperten skal du være logget ind.

Det er heldigvis nemt at oprette en bruger: Det tager to minutter og du kan vælge at bruge enten e-mail, Facebook eller Google som login.

Du kan også logge ind via nedenstående tjenester