Avatar billede nythjem Nybegynder
17. juni 2004 - 13:06 Der er 17 kommentarer og
1 løsning

Upload kun billeder..

Hej Alle!

Jeg har understående glimrende script. Imidlertid er det muligt, at uploade andet end billeder, og det er knap så perfekt.

Hvad skal der stå for kun, at uploade billeder? Jeg har ligeledes et problem med timeout´en. Jeg har prøvet, at indsætte server.timeout flere forskillige steder, men uden held :)

Håber nogle vil hjælpe..

På forhånd tak.

### SCRIPT ###

<%    @EnableSessionState    = False %>

<%    Response.Expires    = 0 %>

<%
Response.Buffer = True

' Connection til database
Set Con = Server.CreateObject("ADODB.Connection")
DBPath = "DBQ=" & server.mappath("../../../database/database.mdb")
Con.Open "DRIVER={Microsoft Access Driver (*.mdb)}; " & DBPath

Sql = "SELECT * FROM avanceretopsaetning"
Set Record =  Con.Execute(Sql)
PictureLink = Record("maildomain")
%>

<%
    Dim ScriptX
    Dim UPLOAD_PATH
        UPLOAD_PATH    = Server.MapPath("../../billeder")

    Dim g_oFso, g_oFolder, g_oFile
        Set g_oFso    = Server.CreateObject("Scripting.FileSystemObject")
        Set g_oFolder    = g_oFso.getFolder(UPLOAD_PATH)

    If (Request.ServerVariables("REQUEST_METHOD") = "POST") Then
        Dim g_oUpload
            Set g_oUpload    = get_upload_files()

        Dim fpos, fcontent
            fcontent    = g_oUpload("upload").Item("content")
        Set g_oFile    = g_oFso.CreateTextFile(UPLOAD_PATH & "\" & extract_filename(g_oUpload("upload").Item("filename")))
        For fpos = 1 to LenB(fcontent)
            g_oFile.Write chr(AscB(MidB(fcontent, fpos, 1)))
        Next
        g_oFile.Close: Set g_oFile    = Nothing

        Response.Redirect Request.ServerVariables("SCRIPT_NAME") & "?upload=on"

    End If

if request.querystring("upload") = "on" then
scriptx = "alert('Upload er udført!');"
end if


    Response.Write "<html><title>UPLOAD AF FILER</title><head></head><body topmargin=""0"" leftmargin=""0"" style=""background-color:transparent;""><script> " & scriptX & " </script><table border=""0"" cellspacing=""0"" cellpadding=""0"" width=""315""><tr><td><form name=""frmUpload"" method=""post"" enctype=""multipart/form-data"" action=""" & Request.ServerVariables("SCRIPT_NAME") & """> <input type=""file"" name=""upload"" style=""font-family: Verdana, Arial, Helvetica; font-size: 10 px;""> <input type=""submit"" value=""Upload"" style=""font-family: Verdana, Arial, Helvetica; font-size: 10 px;""></form></td><tr>"
    Response.Write "<tr><td><img src=""../gfx/1x1.gif"" width=""5"" height=""60""></td><tr><tr><td><form name=myform><select MULTIPLE size=""5"" style=""width:315;height:275; font-family:Verdana, Arial, Helvetica; font-size:10px"" name=""site"" onchange=""if(this.selectedIndex>0)parent.passText(this.value)""><option value=""""></option>"
    For Each g_oFile In g_oFolder.files
    Response.Write "<option value=""http://www." & PictureLink & "/billeder/" & g_oFile.name & """>" & g_oFile.name & "</option>"
    Next
    Response.Write "</select><br><br></td><tr></table></body></html>"

%>

<%
Con.Close
Set Con = Nothing
%>

<%
    Function get_upload_files()
        Dim    upload_object, request_binaries
        Dim position_start, position_end
        Dim boundary, boundary_pos

        Set upload_object    = Server.CreateObject("Scripting.Dictionary")
        request_binaries    = Request.BinaryRead(Request.TotalBytes)
        position_start        = 1
        position_end        = InstrB(position_start, request_binaries, get_byte_string(chr(13)))
        boundary            = MidB(request_binaries, position_start, (position_end - position_start))
        boundary_pos        = InstrB(1, request_binaries, boundary)

        Do Until (boundary_pos = InstrB(request_binaries, boundary & get_byte_string("--")))
            If Not(Response.IsClientConnected) Then Response.End

            Dim name, pos_file

            position_start    = (InstrB(InstrB(boundary_pos, request_binaries, get_byte_string("Content-Disposition")), request_binaries, get_byte_string("name=")) + 6)
            position_end    = InstrB(position_start, request_binaries, get_byte_string(chr(34)))

            name            = get_string(MidB(request_binaries, position_start, (position_end - position_start)))
            pos_file        = InstrB(boundary_pos, request_binaries, get_byte_string("filename="))

            If  ((pos_file <> 0) AND (pos_file < InstrB(position_end, request_binaries, boundary))) Then
                upload_object.Add name, Server.CreateObject("Scripting.Dictionary")

                position_start    = (pos_file + 10)
                position_end    = InstrB(position_start, request_binaries, get_byte_string(chr(34)))
                upload_object.item(name).Add "filename", get_string(MidB(request_binaries, position_start, (position_end - position_start)))

                position_start    = (InstrB(position_end, request_binaries, get_byte_string("Content-Type:")) + 14)
                position_end    = InstrB(position_start, request_binaries, get_byte_string(chr(13)))
                upload_object.item(name).Add "content-type", get_string(MidB(request_binaries, position_start, (position_end - position_start)))

                position_start    = (position_end + 4)
                position_end    = InstrB(position_start, request_binaries, boundary) - 2
                upload_object.item(name).Add "size", ((position_end - position_start))
                upload_object.item(name).Add "content", MidB(request_binaries, position_start, (position_end - position_start))
            End If
            boundary_pos    = InstrB(boundary_pos + LenB(boundary), request_binaries, boundary)
        Loop

        Set get_upload_files = upload_object
    End Function

    Function get_byte_string(str)
        Dim cnt
        For cnt = 1 to Len(str)
            get_byte_string    = get_byte_string & chrB(AscB(Mid(str, cnt, 1)))
        Next
    End Function

    Function get_string(str)
        Dim cnt
        For cnt = 1 to LenB(str)
            get_string    = get_string & chr(AscB(MidB(str, cnt, 1)))
        Next
    End Function

    Function extract_filename(filename)
        extract_filename    = Right(filename, Len(filename) - InStrRev(filename, "\", -1, 1))
    End Function
%>
Avatar billede mortency Nybegynder
17. juni 2004 - 15:16 #1
'Time out
Session.Timeout = 2500
'Det kan være at du ikke får overstyrt innstillingene på webhotellet ditt men prøv å sette denne koden i toppen av dokumentet ditt! Over response.buffer = True

'Sjekker om det er billede......
FileExt = Mid(FilNavn, InstrRev(filename, ".") + 1)

'--------------------------------------------------------------------   
'Check if the file is an JPG eller JPEG OR JPE OR GIF.
'--------------------------------------------------------------------
If LCase(FileExt) <> "jpg" AND LCase(FileExt) <> "jpeg" AND LCase(FileExt) <> "jpe" AND LCase(FileExt) <> "gif" Then
    error = error & "Du må velge enten et JPG, JPEG, JPE eller GIF bilde. \n "
end if

'--------------------------------------------------------------------   
' If error isen`t "", has there become an error. Write it out.
'--------------------------------------------------------------------
If error <> "" Then
    Response.Clear
    %><html>
    <body onload="window.alert('En feil skjedde! \n<% =error %>');
            window.history.back();">
    &nbsp;</body></html><%
    File.delete
    Response.End
End If
Avatar billede mortency Nybegynder
17. juni 2004 - 15:17 #2
Sorry denne linje skal byttes ut:

'Sjekker om det er billede......
FileExt = Mid(FilNavn, InstrRev(filename, ".") + 1)

Med denne:
'Sjekker om det er billede......
FileExt = Mid(filename, InstrRev(filename, ".") + 1)
Avatar billede mortency Nybegynder
17. juni 2004 - 15:17 #3
'Time out
Session.Timeout = 2500
'Det kan være at du ikke får overstyrt innstillingene på webhotellet ditt men prøv å sette denne koden i toppen av dokumentet ditt! Over response.buffer = True

'Sjekker om det er billede......
FileExt = Mid(filename, InstrRev(filename, ".") + 1)

'--------------------------------------------------------------------   
'Check if the file is an JPG eller JPEG OR JPE OR GIF.
'--------------------------------------------------------------------
If LCase(FileExt) <> "jpg" AND LCase(FileExt) <> "jpeg" AND LCase(FileExt) <> "jpe" AND LCase(FileExt) <> "gif" Then
    error = error & "Du må velge enten et JPG, JPEG, JPE eller GIF bilde. \n "
end if

'--------------------------------------------------------------------   
' If error isen`t "", has there become an error. Write it out.
'--------------------------------------------------------------------
If error <> "" Then
    Response.Clear
    %><html>
    <body onload="window.alert('En feil skjedde! \n<% =error %>');
            window.history.back();">
    &nbsp;</body></html><%
    Response.End
End If
Avatar billede nythjem Nybegynder
17. juni 2004 - 15:30 #4
Hej Mortency!

Lige når jeg går ind i filen får jeg straks fejl meddelelsen "Du må velge enten et JPG, JPEG, JPE eller GIF bilde"

Tak fordi du vil hjælpe :)
Avatar billede mortency Nybegynder
17. juni 2004 - 15:38 #5
<%    @EnableSessionState    = False %>

<%    Response.Expires    = 0 %>

<%
Session.Timeout = 2500
Response.Buffer = True

' Connection til database
Set Con = Server.CreateObject("ADODB.Connection")
DBPath = "DBQ=" & server.mappath("../../../database/database.mdb")
Con.Open "DRIVER={Microsoft Access Driver (*.mdb)}; " & DBPath

Sql = "SELECT * FROM avanceretopsaetning"
Set Record =  Con.Execute(Sql)
PictureLink = Record("maildomain")
%>

<%
    Dim ScriptX
    Dim UPLOAD_PATH
        UPLOAD_PATH    = Server.MapPath("../../billeder")

    Dim g_oFso, g_oFolder, g_oFile
        Set g_oFso    = Server.CreateObject("Scripting.FileSystemObject")
        Set g_oFolder    = g_oFso.getFolder(UPLOAD_PATH)

    If (Request.ServerVariables("REQUEST_METHOD") = "POST") Then
        Dim g_oUpload
            Set g_oUpload    = get_upload_files()

        Dim fpos, fcontent
            fcontent    = g_oUpload("upload").Item("content")
        Set g_oFile    = g_oFso.CreateTextFile(UPLOAD_PATH & "\" & extract_filename(g_oUpload("upload").Item("filename")))
        For fpos = 1 to LenB(fcontent)
            g_oFile.Write chr(AscB(MidB(fcontent, fpos, 1)))
        Next
        g_oFile.Close: Set g_oFile    = Nothing

        Response.Redirect Request.ServerVariables("SCRIPT_NAME") & "?upload=on"

    End If

if request.querystring("upload") = "on" then
scriptx = "alert('Upload er udført!');"
end if


    Response.Write "<html><title>UPLOAD AF FILER</title><head></head><body topmargin=""0"" leftmargin=""0"" style=""background-color:transparent;""><script> " & scriptX & " </script><table border=""0"" cellspacing=""0"" cellpadding=""0"" width=""315""><tr><td><form name=""frmUpload"" method=""post"" enctype=""multipart/form-data"" action=""" & Request.ServerVariables("SCRIPT_NAME") & """> <input type=""file"" name=""upload"" style=""font-family: Verdana, Arial, Helvetica; font-size: 10 px;""> <input type=""submit"" value=""Upload"" style=""font-family: Verdana, Arial, Helvetica; font-size: 10 px;""></form></td><tr>"
    Response.Write "<tr><td><img src=""../gfx/1x1.gif"" width=""5"" height=""60""></td><tr><tr><td><form name=myform><select MULTIPLE size=""5"" style=""width:315;height:275; font-family:Verdana, Arial, Helvetica; font-size:10px"" name=""site"" onchange=""if(this.selectedIndex>0)parent.passText(this.value)""><option value=""""></option>"
    For Each g_oFile In g_oFolder.files
    Response.Write "<option value=""http://www." & PictureLink & "/billeder/" & g_oFile.name & """>" & g_oFile.name & "</option>"
    Next
    Response.Write "</select><br><br></td><tr></table></body></html>"

%>

<%
Con.Close
Set Con = Nothing
%>

<%
    Function get_upload_files()
        Dim    upload_object, request_binaries
        Dim position_start, position_end
        Dim boundary, boundary_pos

        Set upload_object    = Server.CreateObject("Scripting.Dictionary")
        request_binaries    = Request.BinaryRead(Request.TotalBytes)
        position_start        = 1
        position_end        = InstrB(position_start, request_binaries, get_byte_string(chr(13)))
        boundary            = MidB(request_binaries, position_start, (position_end - position_start))
        boundary_pos        = InstrB(1, request_binaries, boundary)

        Do Until (boundary_pos = InstrB(request_binaries, boundary & get_byte_string("--")))
            If Not(Response.IsClientConnected) Then Response.End

            Dim name, pos_file

            position_start    = (InstrB(InstrB(boundary_pos, request_binaries, get_byte_string("Content-Disposition")), request_binaries, get_byte_string("name=")) + 6)
            position_end    = InstrB(position_start, request_binaries, get_byte_string(chr(34)))

            name            = get_string(MidB(request_binaries, position_start, (position_end - position_start)))
            pos_file        = InstrB(boundary_pos, request_binaries, get_byte_string("filename="))

            If  ((pos_file <> 0) AND (pos_file < InstrB(position_end, request_binaries, boundary))) Then
                upload_object.Add name, Server.CreateObject("Scripting.Dictionary")

                position_start    = (pos_file + 10)
                position_end    = InstrB(position_start, request_binaries, get_byte_string(chr(34)))
                upload_object.item(name).Add "filename", get_string(MidB(request_binaries, position_start, (position_end - position_start)))

                position_start    = (InstrB(position_end, request_binaries, get_byte_string("Content-Type:")) + 14)
                position_end    = InstrB(position_start, request_binaries, get_byte_string(chr(13)))
                upload_object.item(name).Add "content-type", get_string(MidB(request_binaries, position_start, (position_end - position_start)))

                position_start    = (position_end + 4)
                position_end    = InstrB(position_start, request_binaries, boundary) - 2
                upload_object.item(name).Add "size", ((position_end - position_start))
                upload_object.item(name).Add "content", MidB(request_binaries, position_start, (position_end - position_start))
            End If
            boundary_pos    = InstrB(boundary_pos + LenB(boundary), request_binaries, boundary)
        Loop

        Set get_upload_files = upload_object

FileExt = Mid(FilNavn, InstrRev(filename, ".") + 1)

'--------------------------------------------------------------------   
'Check if the file is an JPG eller JPEG OR JPE OR GIF.
'--------------------------------------------------------------------
If LCase(FileExt) <> "jpg" AND LCase(FileExt) <> "jpeg" AND LCase(FileExt) <> "jpe" AND LCase(FileExt) <> "gif" Then
    error = error & "Du må velge enten et JPG, JPEG, JPE eller GIF bilde. \n "
end if

'--------------------------------------------------------------------   
' If error isen`t "", has there become an error. Write it out.
'--------------------------------------------------------------------
If error <> "" Then
    Response.Clear
    %><html>
    <body onload="window.alert('En feil skjedde! \n<% =error %>');
            window.history.back();">
    &nbsp;</body></html><%
    File.delete
    Response.End
End If

    End Function

    Function get_byte_string(str)
        Dim cnt
        For cnt = 1 to Len(str)
            get_byte_string    = get_byte_string & chrB(AscB(Mid(str, cnt, 1)))
        Next
    End Function

    Function get_string(str)
        Dim cnt
        For cnt = 1 to LenB(str)
            get_string    = get_string & chr(AscB(MidB(str, cnt, 1)))
        Next
    End Function

    Function extract_filename(filename)
        extract_filename    = Right(filename, Len(filename) - InStrRev(filename, "\", -1, 1))
    End Function
%>
Avatar billede nythjem Nybegynder
17. juni 2004 - 15:49 #6
Hmm..

Jeg har prøvet, at uploade en .jpg fil, men får følgende fejl:

Microsoft VBScript runtime error '800a01a8'

Object required: "

Linie 125 (    File.delete)
Avatar billede haps Nybegynder
17. juni 2004 - 15:50 #7
kan du ikke lave en funktion der går ind og chekker på filtypen, og laver en if else på alle de formater der må uploades!?
Avatar billede mortency Nybegynder
17. juni 2004 - 15:50 #8
Du må fjerne dette... sorry

'--------------------------------------------------------------------   
' If error isen`t "", has there become an error. Write it out.
'--------------------------------------------------------------------
If error <> "" Then
    Response.Clear
    %><html>
    <body onload="window.alert('En feil skjedde! \n<% =error %>');
            window.history.back();">
    &nbsp;</body></html><%
    File.delete <------------------ FJERN DENNE LINJE!!!!!!!
    Response.End
End If
Avatar billede haps Nybegynder
17. juni 2004 - 15:51 #9
damn... my bad... fik ikke lige læst det hele igennem...
Avatar billede mortency Nybegynder
17. juni 2004 - 15:53 #10
virker det?
Avatar billede nythjem Nybegynder
17. juni 2004 - 15:57 #11
Okay,

nu har jeg fjernet linien, men når jeg så uploader en jpg fil, så får jeg stadig javascript fejlen :(

Se evt. her selv.. http://www.nythjem.dk/admin/popups/upload.asp
Avatar billede mortency Nybegynder
17. juni 2004 - 16:00 #12
Prøv dette...


<%    @EnableSessionState    = False %>

<%    Response.Expires    = 0 %>

<%
Session.Timeout = 2500
Response.Buffer = True

' Connection til database
Set Con = Server.CreateObject("ADODB.Connection")
DBPath = "DBQ=" & server.mappath("../../../database/database.mdb")
Con.Open "DRIVER={Microsoft Access Driver (*.mdb)}; " & DBPath

Sql = "SELECT * FROM avanceretopsaetning"
Set Record =  Con.Execute(Sql)
PictureLink = Record("maildomain")
%>

<%
    Dim ScriptX
    Dim UPLOAD_PATH
        UPLOAD_PATH    = Server.MapPath("../../billeder")

    Dim g_oFso, g_oFolder, g_oFile
        Set g_oFso    = Server.CreateObject("Scripting.FileSystemObject")
        Set g_oFolder    = g_oFso.getFolder(UPLOAD_PATH)

    If (Request.ServerVariables("REQUEST_METHOD") = "POST") Then
        Dim g_oUpload
            Set g_oUpload    = get_upload_files()

        Dim fpos, fcontent
            fcontent    = g_oUpload("upload").Item("content")
        Set g_oFile    = g_oFso.CreateTextFile(UPLOAD_PATH & "\" & extract_filename(g_oUpload("upload").Item("filename")))
        For fpos = 1 to LenB(fcontent)
            g_oFile.Write chr(AscB(MidB(fcontent, fpos, 1)))
        Next
        g_oFile.Close: Set g_oFile    = Nothing

        Response.Redirect Request.ServerVariables("SCRIPT_NAME") & "?upload=on"

    End If

if request.querystring("upload") = "on" then
scriptx = "alert('Upload er udført!');"
end if


    Response.Write "<html><title>UPLOAD AF FILER</title><head></head><body topmargin=""0"" leftmargin=""0"" style=""background-color:transparent;""><script> " & scriptX & " </script><table border=""0"" cellspacing=""0"" cellpadding=""0"" width=""315""><tr><td><form name=""frmUpload"" method=""post"" enctype=""multipart/form-data"" action=""" & Request.ServerVariables("SCRIPT_NAME") & """> <input type=""file"" name=""upload"" style=""font-family: Verdana, Arial, Helvetica; font-size: 10 px;""> <input type=""submit"" value=""Upload"" style=""font-family: Verdana, Arial, Helvetica; font-size: 10 px;""></form></td><tr>"
    Response.Write "<tr><td><img src=""../gfx/1x1.gif"" width=""5"" height=""60""></td><tr><tr><td><form name=myform><select MULTIPLE size=""5"" style=""width:315;height:275; font-family:Verdana, Arial, Helvetica; font-size:10px"" name=""site"" onchange=""if(this.selectedIndex>0)parent.passText(this.value)""><option value=""""></option>"
    For Each g_oFile In g_oFolder.files
    Response.Write "<option value=""http://www." & PictureLink & "/billeder/" & g_oFile.name & """>" & g_oFile.name & "</option>"
    Next
    Response.Write "</select><br><br></td><tr></table></body></html>"

%>

<%
Con.Close
Set Con = Nothing
%>

<%
    Function get_upload_files()
        Dim    upload_object, request_binaries
        Dim position_start, position_end
        Dim boundary, boundary_pos

        Set upload_object    = Server.CreateObject("Scripting.Dictionary")
        request_binaries    = Request.BinaryRead(Request.TotalBytes)
        position_start        = 1
        position_end        = InstrB(position_start, request_binaries, get_byte_string(chr(13)))
        boundary            = MidB(request_binaries, position_start, (position_end - position_start))
        boundary_pos        = InstrB(1, request_binaries, boundary)

        Do Until (boundary_pos = InstrB(request_binaries, boundary & get_byte_string("--")))
            If Not(Response.IsClientConnected) Then Response.End

            Dim name, pos_file

            position_start    = (InstrB(InstrB(boundary_pos, request_binaries, get_byte_string("Content-Disposition")), request_binaries, get_byte_string("name=")) + 6)
            position_end    = InstrB(position_start, request_binaries, get_byte_string(chr(34)))

            name            = get_string(MidB(request_binaries, position_start, (position_end - position_start)))
            pos_file        = InstrB(boundary_pos, request_binaries, get_byte_string("filename="))

            If  ((pos_file <> 0) AND (pos_file < InstrB(position_end, request_binaries, boundary))) Then
                upload_object.Add name, Server.CreateObject("Scripting.Dictionary")

                position_start    = (pos_file + 10)
                position_end    = InstrB(position_start, request_binaries, get_byte_string(chr(34)))
                upload_object.item(name).Add "filename", get_string(MidB(request_binaries, position_start, (position_end - position_start)))

                position_start    = (InstrB(position_end, request_binaries, get_byte_string("Content-Type:")) + 14)
                position_end    = InstrB(position_start, request_binaries, get_byte_string(chr(13)))
                upload_object.item(name).Add "content-type", get_string(MidB(request_binaries, position_start, (position_end - position_start)))

                position_start    = (position_end + 4)
                position_end    = InstrB(position_start, request_binaries, boundary) - 2
                upload_object.item(name).Add "size", ((position_end - position_start))
                upload_object.item(name).Add "content", MidB(request_binaries, position_start, (position_end - position_start))
            End If
            boundary_pos    = InstrB(boundary_pos + LenB(boundary), request_binaries, boundary)
        Loop

        Set get_upload_files = upload_object

FileExt = Mid(filename, InstrRev(filename, ".") + 1)

'--------------------------------------------------------------------   
'Check if the file is an JPG eller JPEG OR JPE OR GIF.
'--------------------------------------------------------------------
If LCase(FileExt) <> "jpg" AND LCase(FileExt) <> "jpeg" AND LCase(FileExt) <> "jpe" AND LCase(FileExt) <> "gif" Then
    error = error & "Du må velge enten et JPG, JPEG, JPE eller GIF bilde. \n "
end if

'--------------------------------------------------------------------   
' If error isen`t "", has there become an error. Write it out.
'--------------------------------------------------------------------
If error <> "" Then
    Response.Clear
    %><html>
    <body onload="window.alert('En feil skjedde! \n<% =error %>');
            window.history.back();">
    &nbsp;</body></html><%
    File.delete
    Response.End
End If

    End Function

    Function get_byte_string(str)
        Dim cnt
        For cnt = 1 to Len(str)
            get_byte_string    = get_byte_string & chrB(AscB(Mid(str, cnt, 1)))
        Next
    End Function

    Function get_string(str)
        Dim cnt
        For cnt = 1 to LenB(str)
            get_string    = get_string & chr(AscB(MidB(str, cnt, 1)))
        Next
    End Function

    Function extract_filename(filename)
        extract_filename    = Right(filename, Len(filename) - InStrRev(filename, "\", -1, 1))
    End Function
%>
Avatar billede mortency Nybegynder
17. juni 2004 - 16:00 #13
Fjern file.delete --> glemte den igjen..
Avatar billede nythjem Nybegynder
17. juni 2004 - 16:03 #14
:) Ja, jeg så den selv :)

Den giver desværre stadig fejl, når jeg uploader en jpg..
Avatar billede mortency Nybegynder
17. juni 2004 - 16:15 #15
Problemet er nok at den ikke får tak i FilName
i denne linje:

FileExt = Mid(filename, InstrRev(filename, ".") + 1)

Kanskje:
filname = extract_filename(g_oUpload("upload").Item("filename"))
FileExt = Mid(filename, InstrRev(filename, ".") + 1)
Avatar billede mortency Nybegynder
17. juni 2004 - 16:16 #16
Kanskje dette:....

<%    @EnableSessionState    = False %>

<%    Response.Expires    = 0 %>

<%
Session.Timeout = 2500
Response.Buffer = True

' Connection til database
Set Con = Server.CreateObject("ADODB.Connection")
DBPath = "DBQ=" & server.mappath("../../../database/database.mdb")
Con.Open "DRIVER={Microsoft Access Driver (*.mdb)}; " & DBPath

Sql = "SELECT * FROM avanceretopsaetning"
Set Record =  Con.Execute(Sql)
PictureLink = Record("maildomain")
%>

<%
    Dim ScriptX
    Dim UPLOAD_PATH
        UPLOAD_PATH    = Server.MapPath("../../billeder")

    Dim g_oFso, g_oFolder, g_oFile
        Set g_oFso    = Server.CreateObject("Scripting.FileSystemObject")
        Set g_oFolder    = g_oFso.getFolder(UPLOAD_PATH)

    If (Request.ServerVariables("REQUEST_METHOD") = "POST") Then
        Dim g_oUpload
            Set g_oUpload    = get_upload_files()

        Dim fpos, fcontent
            fcontent    = g_oUpload("upload").Item("content")
        Set g_oFile    = g_oFso.CreateTextFile(UPLOAD_PATH & "\" & extract_filename(g_oUpload("upload").Item("filename")))
        For fpos = 1 to LenB(fcontent)
            g_oFile.Write chr(AscB(MidB(fcontent, fpos, 1)))
        Next
        g_oFile.Close: Set g_oFile    = Nothing

        Response.Redirect Request.ServerVariables("SCRIPT_NAME") & "?upload=on"

    End If

if request.querystring("upload") = "on" then
scriptx = "alert('Upload er udført!');"
end if


    Response.Write "<html><title>UPLOAD AF FILER</title><head></head><body topmargin=""0"" leftmargin=""0"" style=""background-color:transparent;""><script> " & scriptX & " </script><table border=""0"" cellspacing=""0"" cellpadding=""0"" width=""315""><tr><td><form name=""frmUpload"" method=""post"" enctype=""multipart/form-data"" action=""" & Request.ServerVariables("SCRIPT_NAME") & """> <input type=""file"" name=""upload"" style=""font-family: Verdana, Arial, Helvetica; font-size: 10 px;""> <input type=""submit"" value=""Upload"" style=""font-family: Verdana, Arial, Helvetica; font-size: 10 px;""></form></td><tr>"
    Response.Write "<tr><td><img src=""../gfx/1x1.gif"" width=""5"" height=""60""></td><tr><tr><td><form name=myform><select MULTIPLE size=""5"" style=""width:315;height:275; font-family:Verdana, Arial, Helvetica; font-size:10px"" name=""site"" onchange=""if(this.selectedIndex>0)parent.passText(this.value)""><option value=""""></option>"
    For Each g_oFile In g_oFolder.files
    Response.Write "<option value=""http://www." & PictureLink & "/billeder/" & g_oFile.name & """>" & g_oFile.name & "</option>"
    Next
    Response.Write "</select><br><br></td><tr></table></body></html>"

%>

<%
Con.Close
Set Con = Nothing
%>

<%
    Function get_upload_files()
        Dim    upload_object, request_binaries
        Dim position_start, position_end
        Dim boundary, boundary_pos

        Set upload_object    = Server.CreateObject("Scripting.Dictionary")
        request_binaries    = Request.BinaryRead(Request.TotalBytes)
        position_start        = 1
        position_end        = InstrB(position_start, request_binaries, get_byte_string(chr(13)))
        boundary            = MidB(request_binaries, position_start, (position_end - position_start))
        boundary_pos        = InstrB(1, request_binaries, boundary)

        Do Until (boundary_pos = InstrB(request_binaries, boundary & get_byte_string("--")))
            If Not(Response.IsClientConnected) Then Response.End

            Dim name, pos_file

            position_start    = (InstrB(InstrB(boundary_pos, request_binaries, get_byte_string("Content-Disposition")), request_binaries, get_byte_string("name=")) + 6)
            position_end    = InstrB(position_start, request_binaries, get_byte_string(chr(34)))

            name            = get_string(MidB(request_binaries, position_start, (position_end - position_start)))
            pos_file        = InstrB(boundary_pos, request_binaries, get_byte_string("filename="))

            If  ((pos_file <> 0) AND (pos_file < InstrB(position_end, request_binaries, boundary))) Then
                upload_object.Add name, Server.CreateObject("Scripting.Dictionary")

                position_start    = (pos_file + 10)
                position_end    = InstrB(position_start, request_binaries, get_byte_string(chr(34)))
                upload_object.item(name).Add "filename", get_string(MidB(request_binaries, position_start, (position_end - position_start)))

                position_start    = (InstrB(position_end, request_binaries, get_byte_string("Content-Type:")) + 14)
                position_end    = InstrB(position_start, request_binaries, get_byte_string(chr(13)))
                upload_object.item(name).Add "content-type", get_string(MidB(request_binaries, position_start, (position_end - position_start)))

                position_start    = (position_end + 4)
                position_end    = InstrB(position_start, request_binaries, boundary) - 2
                upload_object.item(name).Add "size", ((position_end - position_start))
                upload_object.item(name).Add "content", MidB(request_binaries, position_start, (position_end - position_start))
            End If
            boundary_pos    = InstrB(boundary_pos + LenB(boundary), request_binaries, boundary)
        Loop

        Set get_upload_files = upload_object

    End Function

    Function get_byte_string(str)
        Dim cnt
        For cnt = 1 to Len(str)
            get_byte_string    = get_byte_string & chrB(AscB(Mid(str, cnt, 1)))
        Next
    End Function

    Function get_string(str)
        Dim cnt
        For cnt = 1 to LenB(str)
            get_string    = get_string & chr(AscB(MidB(str, cnt, 1)))
        Next
    End Function

    Function extract_filename(filename)
        extract_filename    = Right(filename, Len(filename) - InStrRev(filename, "\", -1, 1))

FileExt = Mid(filename, InstrRev(filename, ".") + 1)

'--------------------------------------------------------------------   
'Check if the file is an JPG eller JPEG OR JPE OR GIF.
'--------------------------------------------------------------------
If LCase(FileExt) <> "jpg" AND LCase(FileExt) <> "jpeg" AND LCase(FileExt) <> "jpe" AND LCase(FileExt) <> "gif" Then
    error = error & "Du må velge enten et JPG, JPEG, JPE eller GIF bilde. \n "
end if

'--------------------------------------------------------------------   
' If error isen`t "", has there become an error. Write it out.
'--------------------------------------------------------------------
If error <> "" Then
    Response.Clear
    %><html>
    <body onload="window.alert('En feil skjedde! \n<% =error %>');
            window.history.back();">
    &nbsp;</body></html><%
    Response.End
End If
    End Function
%>
Avatar billede nythjem Nybegynder
17. juni 2004 - 16:20 #17
PERFEKT!!!

Jette Bra, og hele motivitten.. Flot Morten :)

Tusinde tusinde tusinde tak for hjælpen :)
Avatar billede mortency Nybegynder
17. juni 2004 - 16:23 #18
Bare hyggelig... :-)
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