Avatar billede mccannon Nybegynder
17. maj 2002 - 23:15 Der er 9 kommentarer og
1 løsning

Filesystem object - syntax

Hejsa

Hvad er syntaxen når man skal copiere filer fra et sted til et andet sted på serveren ??

den her måde melder ihvertfald fejl
Source = "_private/" & Session("navn") & ".jpg"
        Desti = "images/" & Session("navn") & ".jpg"
       
        Set FSO = server.createobject("scripting.filesystemobject")
        FSO.CopyFile(Source,Desti,True)
Avatar billede dta Nybegynder
17. maj 2002 - 23:22 #1
Set FSO = server.createobject("scripting.filesystemobject")
Set objFile = FSO.Getfile(server.mappath(Source))
objFile.copy(server.mappath(Desti), ???[overskrib true/false]???)
Avatar billede mccannon Nybegynder
17. maj 2002 - 23:28 #2
Der kan ikke bruges parenteser ved kald af en Sub
upload.asp, line 30, column 37

:-(
Avatar billede dta Nybegynder
17. maj 2002 - 23:33 #3
Lad mig lige se din kode
Avatar billede mccannon Nybegynder
17. maj 2002 - 23:37 #4
oki..

upload.asp :
----------------
<!--#include file="fileupload_class.inc"-->
<%
action = request.querystring("action")
Dim ul
            Set ul = New FileUpload
            ul.Upload()
            Set ul = Nothing



response.write session("navn")
If action = 3 then
       
        set Conn = server.createobject("ADODB.connection")
        Conn.open "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & server.mappath("../database/indhold.mdb")    
   
        SQL = "Update tblupload Set "
        SQL = SQL & "billednavn='" & Session("navn") & "' "
        SQL = SQL & "Where ID = " & Session("ID")
       
        Conn.execute(SQL)
       
        Source = "_private/" & Session("navn") & ".jpg"
        Desti = "images/" & Session("navn") & ".jpg"
                   
        Set FSO = server.createobject("scripting.filesystemobject")
        Set File = FSO2.Getfile(server.mappath(Source))
        File.copy(server.mappath(Desti),True)
       
        session("ID") = ""
        Session("navn") = ""
   
        conn.close
        set conn = nothing
       
       
    response.redirect "forside.asp?id=50" & "&menuID=3" & "&UmenuID=50" & "&besked=54"
    end if
   
   
%>

FileUpload_class.inc.:
-------------------------
<% response.buffer = true %>
<%
response.expires = 0

Class FileUpload

    Private strThisPage, lngUploadSize, boolAllowOverwrite
    Private UploadRequest, arrExt, strUploadDir

    Public Property LET Extensions(byVal arrayInput)
        arrExt = arrayInput
    End Property

    Public Property LET UploadDirectory(byVal strInput)
        strUploadDir = strInput
    End Property

    Public Property LET AllowOverWrite(byVal boolInput)
        boolAllowOverwrite = boolInput
    End Property

    Public Property LET UploadSize(byVal lngInput)
        lngUploadSize = CLng( lngInput )
    End Property

    Public Property GET Extensions()
        If IsArray( arrExt ) then
            Extensions = arrExt
        ElseIf Len(arrExt) = 1 AND arrExt = "*" Then
            Extensions = "*"
        Else

' ********************************************************************
' ******** Her deklareres de gyldige extensions i et array  **********
' ********************************************************************
            Extensions = Array(".jpg")
        End If
    End Property

    Public Property GET UploadDirectory()
        If strUploadDir = Empty then

' ********************************************************************
' ******** Her sættes biblioteket hvor filerne uploades til **********
' ********************************************************************

            UploadDirectory = Server.Mappath("images/")
        Else
            UploadDirectory = strUploadDir
        End If
    End Property

    Public Property GET AllowOverWrite()
        ' allow file overwrite
        AllowOverWrite = CBool( boolAllowOverwrite )
    End Property


' ********************************************************************
' ******** Her sættes max upload størrelse på uploadfilen i byte *****
' ********************************************************************

    Public Property GET UploadSize()
        ' set maximum file size
        If lngUploadSize = 0 then
            UploadSize = 100000
        Else
            UploadSize = lngUploadSize
        End If
    End Property



    Private Sub Class_Initialize()
        strThisPage  = request.serverVariables("PATH_INFO")
        Call ClearVariables()
        Call ClearDictionary()
    End Sub

    Private Sub Class_Terminate()
        strThisPage  = ""
        Call ClearVariables()
        Call ClearDictionary()
    End Sub

    Public Default Sub Upload()
        Dim lngTotalBytes
        On Error Resume Next
        lngTotalBytes = Request.TotalBytes
        If lngTotalBytes <= 0 Then
            Call ShowForm()
        ElseIf lngTotalBytes > 0 And lngTotalBytes <= UploadSize Then
            Call UploadBinary( lngTotalBytes )
        ElseIf lngTotalBytes > UploadSize Then
            Call FileTooBig_Error()
        Else
            Call ShowForm()
        End If
        On Error GoTo 0
    End Sub



' ***************************************************************************
' ******** Her bestemmes det hvorvidt der tillades overskrivning af filer ***
' ***************************************************************************
    Private Sub ClearVariables()
        lngUploadSize = 0
        arrExt        = Empty
        strUploadDir  = Empty
        boolAllowOverwrite = True
    End Sub

    Private Sub ClearDictionary()
        Set UploadRequest = Server.CreateObject("Scripting.Dictionary")
        UploadRequest.RemoveAll
        Set UploadRequest = Nothing
    End Sub

    Private Sub QuitUpload()
        Response.Write "<P><CENTER><A HREF=""" & strThisPage & """>"
        Response.Write "<B>Try Again</B></A></CENTER></P>"
    End Sub

    Private Sub UploadBinary(byVal MaxBytes)
        Dim byteCount, RequestBin, filepathext
        Dim ContentType, filePathName, filename, boolAllowed
        boolAllowed = False
        byteCount = MaxBytes
        RequestBin = Request.BinaryRead(byteCount)
        Set UploadRequest = Server.CreateObject("Scripting.Dictionary")
        BuildUploadRequest  RequestBin
        contentType = UploadRequest.Item("blob").Item("ContentType")
        filepathname = UploadRequest.Item("blob").Item("FileName")
        filename = Right(filepathname,Len(filepathname)-InstrRev(filepathname,"\"))
        filepathext = Right(filepathname, 4)
        If IsArray(Extensions) Then
            boolAllowed = ExtensionCheck( filepathext )
        ElseIf Extensions = "*" Then
            boolAllowed = True
        End If
        If boolAllowed Then
        filename = Session("navn") & filepathext
        session("filnavn") = filename
        filename = UploadDirectory & "\" & filename
        Call WriteUploadFile( filename, UploadRequest.Item("blob").Item("Value") )
        Else
        Call BadExtension_Error()
        End If
    End Sub

    Private Sub WriteUploadFile(byVal NAME, byVal CONTENTS)
        dim ScriptObject, i, NewFile
        Set ScriptObject = Server.CreateObject("Scripting.FileSystemObject")
        If ScriptObject.FolderExists( UploadDirectory ) Then
            If NOT AllowOverWrite AND ScriptObject.FileExists( NAME ) Then
                Set ScriptObject = Nothing
                Call FileAlreadyExists_Error()
                Exit Sub
            End If
            Set NewFile = ScriptObject.CreateTextFile( NAME )
            For i = 1 to LenB( CONTENTS )
                NewFile.Write chr( AscB( MidB( CONTENTS, i, 1) ) )
            Next
            NewFile.Close
            Set NewFile = Nothing
            Call Success( NAME )
        Else
            Set ScriptObject = Nothing
            Call UploadDirNotFound_Error()
            Exit Sub
        End If
        Set ScriptObject = Nothing
    End Sub

    Private Function ExtensionCheck(byVal EXT)
        Dim Item
        For each item in Extensions
            if LCase( EXT ) = LCase( Item ) Then
                ExtensionCheck = True
                Exit Function
            end if
        Next
        ExtensionCheck = False
    End Function



' ********************************************************************
' ******** Herunder kommer samtlige forskellige brugeroplysninger, ***
' ******** afhængig af brugerens opførsel ****************************
' ********************************************************************
    Private Sub Success(byVal FILE)
    Dim strRoot
    strRoot = LCase( Server.Mappath("/") )
    FILE = LCase( FILE )
    FILE = Replace( Replace( FILE, strRoot, "" ), "\", "/" )
    Response.Write "<H1>Upload popo</H1>"
    Response.Write "<P><BIG><B>" & FILE & "</B></BIG></P>"
    Response.redirect "upload.asp?action=3"
    End Sub

    Private Sub ShowForm()
        ' display the upload form and let the
        ' user know what they can and cannot upload
        Dim tmp, item
        With Response
            .Write "<H1>File Upload</H1>"
            .Write "<P>You can currently add any file of type: "
            tmp = ""
            If IsArray(Extensions) Then
                For Each Item In Extensions
                    tmp = tmp & "*" & Item & ", "
                Next
                tmp = left( tmp, Len(tmp) - 2 )
            Else
                tmp = "All file types allowed"
            End If
            .Write tmp & "<BR>"
            .Write "Having a maximum size of: ~ "
            .Write Round( UploadSize / 1024, 1 ) & " k</P>"
            .Write "<FORM ENCTYPE=""multipart/form-data"" ACTION="""
            .Write strThisPage & """ METHOD=""POST"">" & vbCrLf
            .write "<table border='1'>"
            .Write "<tr><td>Please select a file to upload "
            .Write "from your computer:</td></tr>"
            .Write "<tr><td>Your Picture.:</td><td><INPUT TYPE=FILE NAME=""blob""></td></tr>"
            .Write "<tr><td>Upload Picture and description</td><td><INPUT TYPE=SUBMIT VALUE=""Upload""></td></tr>"
            .write "</table>"
            .Write "</FORM>" & vbCrLf
        End With
    End Sub

    Private Sub FileTooBig_Error()
        Response.Write "<H1>Upload File Too Large...</H1>"
        Response.Write "<P>You are currently limited to "
        Response.Write "uploading a maximum of "
        On Error Resume Next
        Response.Write Round( UploadSize / 1024, 1 ) & " k.</P>"
        On Error GoTo 0
        Call QuitUpload()
    End Sub

    Private Sub UploadDirNotFound_Error()
        Response.Write "<H1>Upload Directory Not Found ...</H1>"
        Response.Write "<P>The Specified Upload Directory Cannot Be Found.</P>"
        Call QuitUpload()
    End Sub

    Private Sub FileAlreadyExists_Error()
        Response.Write "<H1>Specified File Already Exists ...</H1>"
        Response.Write "<P>File OverWrite Disabled.</P>"
        Response.Write "<P>Rename the file on your computer and re-upload...</P>"
        Call QuitUpload()
    End Sub

    Private Sub BadExtension_Error()
        Dim Item, tmp
        Response.Write "<H1>Bad File Type...</H1>"
        Response.Write "<P>You are currently limited to "
        Response.Write "uploading only the following types of files:</P>"
        Response.Write "<P>"
        tmp = ""
        For Each Item In Extensions
            tmp = tmp & "*" & Item & ", "
        Next
        tmp = left( tmp, Len(tmp) - 2 )
        Response.Write "<P>" & tmp & "</P>"
        Call QuitUpload()
    End Sub

    Private Function getByteString(StringStr)
        dim char, i
        For i = 1 to Len(StringStr)
            char = Mid(StringStr,i,1)
            getByteString = getByteString & chrB(AscB(char))
        Next
    End Function

    Private Function getString(StringBin)
        dim intCount
        getString =""
        For intCount = 1 to LenB(StringBin)
            getString = getString & chr(AscB(MidB(StringBin,intCount,1)))
        Next
    End Function

    Private Sub BuildUploadRequest(RequestBin)
        dim PosBeg,PosEnd,boundary,boundaryPos,Pos,Name,PosFile
        dim PosBound,FileName,ContentType,Value
        PosBeg = 1
        PosEnd = InstrB(PosBeg,RequestBin,getByteString(chr(13)))
        boundary = MidB(RequestBin,PosBeg,PosEnd-PosBeg)
        boundaryPos = InstrB(1,RequestBin,boundary)
        Do until (boundaryPos=InstrB(RequestBin,boundary & getByteString("--")))
            Dim UploadControl
            Set UploadControl = Server.CreateObject("Scripting.Dictionary")
            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)
            If  PosFile<>0 AND (PosFile<PosBound) Then
                PosBeg = PosFile + 10
                PosEnd =  InstrB(PosBeg,RequestBin,getByteString(chr(34)))
                FileName = getString(MidB(RequestBin,PosBeg,PosEnd-PosBeg))
                UploadControl.Add "FileName", FileName
                Pos = InstrB(PosEnd,RequestBin,getByteString("Content-Type:"))
                PosBeg = Pos+14
                PosEnd = InstrB(PosBeg,RequestBin,getByteString(chr(13)))
                ContentType = getString(MidB(RequestBin,PosBeg,PosEnd-PosBeg))
                UploadControl.Add "ContentType",ContentType
                PosBeg = PosEnd+4
                PosEnd = InstrB(PosBeg,RequestBin,boundary)-2
                Value = MidB(RequestBin,PosBeg,PosEnd-PosBeg)
            Else
                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
            UploadControl.Add "Value" , Value   
            UploadRequest.Add name, UploadControl   
            BoundaryPos=InstrB(BoundaryPos+LenB(boundary),RequestBin,boundary)
        Loop
    End Sub
End Class

%>
Avatar billede mccannon Nybegynder
17. maj 2002 - 23:38 #5
FSO2.Getfile(server.mappath(Source))

er rettet :)
Avatar billede mccannon Nybegynder
17. maj 2002 - 23:38 #6
FOS2 til FSO altså..koden virker stadig ikke..
Avatar billede dta Nybegynder
17. maj 2002 - 23:42 #7
Set File = FSO2.Getfile(server.mappath(Source))
->
Set File = FSO.Getfile(server.mappath(Source))
Avatar billede mccannon Nybegynder
17. maj 2002 - 23:43 #8
FSO /FSO2 er fixet..hjalp ingenting :(
Avatar billede mccannon Nybegynder
17. maj 2002 - 23:55 #9
har lige prøvet at flytte den kode hvor jeg flytter filen over på en anden side..hvor fileupload_class.inc ikke er included..for at se om det var noget gik gi konflikt med class.inc filen...men ak..det hjalp heller ikke
Avatar billede mccannon Nybegynder
18. maj 2002 - 22:55 #10
f
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