Visualizzazione dei risultati da 1 a 2 su 2
  1. #1

    Problema Upload di file

    Ragazzi buongiorno a tutti, ho un problema con l'upload di file.
    Ho una semplice form che punta ad una pagina che raccoglie i campi e fa l'upload dei dati e di un file qualsiasi. Lo script che utilizzo per stabilire il percorso del file è il seguente e FUNZIONA PERFETTAMENTE:

    Form

    Ho un form con dei campi compilati tramite un recordset

    Codice PHP:
        <form id="myForm" class="uniform" method="post" action="modifica_logo.asp?idazienda=<%=rs("idazienda")%>" enctype="multipart/form-data"
    Pagina che recupera il percorso del file e salva i dati

    Codice PHP:
    <%
    id request.querystring("id")

    Set um = New UploadManager
    um
    .ParseRequest(Request)

    ' File 1
    Set a = um.GetItem("logo")
    a.Save Server.MapPath("\public\"), "My1_" & a.FileNameNome=a.FileName

    poi dopo faccio il salvataggio del percorso nel db e funziona..... 
    Il mio problema sorge nel momento in cui voglio cambiare la destinazione del file in base alla variabile "folder" che mi porto in querystring

    Form modificato per portarmi dietro il nome della cartella

    Codice PHP:
        <form id="myForm" class="uniform" method="post" action="modifica_logo.asp?idazienda=<%=rs("idazienda")%>&folder=<%=rs("folder")%>" enctype="multipart/form-data"
    Script upload modificato in base al mio scopo


    Codice PHP:
    <%
    id request.querystring("id")
    folder request.querystring("folder")

    Set um = New UploadManager
    um
    .ParseRequest(Request)

    ' File 1
    Set a = um.GetItem("logo")
    a.Save Server.MapPath("\public\" & folder & ""), "My1_" & a.FileNameNome=a.FileName 
    Ecco l'errore che mi da:

    Microsoft VBScript runtime error '800a01b6'
    Object doesn't support this property or method: 'a.FileNameNome'
    /amministrazione/modifica_logo.asp, line 11
    http://www.generationweb.it <--- web site

  2. #2
    Vi inserisco anche il codice dell'upload dei file che ho incluso come "uploadmanager.asp"

    Codice PHP:
    Class UploadManager
        
        
    Public TypologyField
        
    Public TypologyFile
        
        
    Private m_itemlist    ' array: key1, [val1, val1, val1], key2, [val2], ... 
        
        Sub Class_Initialize
            TypologyField = 0
            TypologyFile = 1
        End Sub 
        
        Public Function ParseRequest(r)
            Dim contenttypelist, rs, requeststring, boundry, data, i, infoend, info, value, item, ii, keyexists, iv
            ReDim m_itemlist(-1)
            contenttypelist = Split(LCase(r.ServerVariables("HTTP_CONTENT_TYPE")), ";")
            If InStr(contenttypelist(0), "multipart/form-data") = 0 Then Err.Raise 513, "UploadManager", "Form non di tipo ""multipart/form-data"""
            Set rs = Server.CreateObject("ADODB.Recordset")
            rs.Fields.Append "mBin", 201, r.TotalBytes 
            rs.Open()
            rs.AddNew()
            rs("mBin").AppendChunk r.BinaryRead(r.TotalBytes)
            rs.Update()
            requeststring = CStr(rs("mBin"))
            boundry = Split(contenttypelist(1), "=")(1)
            data = Split(requeststring, boundry)
            For i = 0 To UBound(data)
                infoend = InStr(data(i), vbCrLf & vbCrLf)    '
    two sets of crlf mark the end of the information about this fieldeverything after that is the value
                
    If infoend 1 Then
                    info 
    Mid(data(i), 2infoend 2)        'pull the info for this field, minus the stuff at the ends...
                    value = Mid(data(i), infoend + 4, Len(data(i)) - infoend - 7)        '
    skip the crlf pairs at the start and the crlf-- at the endlength Len(data(i)) - - (infoend 4) + Len(data(i)) - infoend Len(data(i)) - infoend 7
                    
    If InStr(LCase(info), "filename=") > 0 Then
                        Set item 
    = New RequestItemFile
                        item
    .Info info
                        item
    .Value value
                    
    Else
                        
    Set item = New RequestItem
                        item
    .Info info
                        item
    .Value value
                    End 
    If
                    
    ' field exists in m_itemlist?
                    keyexists = False
                    For ii = 0 To UBound(m_itemlist) Step 2
                        If m_itemlist(ii) = LCase(item.Name) Then
                            iv = m_itemlist(ii + 1)
                            ReDim Preserve iv(UBound(iv) + 1)
                            Set iv(UBound(iv)) = item
                            m_itemlist(ii + 1) = iv
                            keyexists = True
                            Exit For
                        End If
                    Next
                    If Not keyexists Then
                        ReDim Preserve m_itemlist(UBound(m_itemlist) + 2)
                        m_itemlist(UBound(m_itemlist) - 1) = LCase(item.Name)
                        m_itemlist(UBound(m_itemlist)) = Array(item)
                    End If
                End If
            Next
        End Function
        
        Public Function GetItem(name)    ' 
    return first field
            Dim i
            Set GetItem 
    Nothing
            
    For 0 To UBound(m_itemlistStep 2
                
    If m_itemlist(i) = LCase(nameThen
                    Set GetItem 
    m_itemlist(1)(0)
                    Exit Function
                
    End If
            
    Next
        End 
    Function
        
        Public Function 
    GetItemList(name)
            
    Dim i
            GetItemList 
    = Array()
            For 
    0 To UBound(m_itemlistStep 2
                
    If m_itemlist(i) = LCase(nameThen
                    GetItemList 
    m_itemlist(1)
                    Exit Function
                
    End If
            
    Next
        End 
    Function

    End Class

    Class 
    RequestItem

        
    Public Info
        
    Public Value
        
        
    Public Property Get Name
            Dim s
    e
            s 
    InStr(Info"name=""") + Len("name=""")
            If 
    InStrRev(Info""";") > 0 Then
                e 
    InStrRev(Info""";") - 1
            
    Else
                
    InStrRev(Info"""") - 1
            End 
    If
            
    Name Mid(Infos1)
        
    End Property
        
        
    Public Property Get Typology
            Dim um
            Set um 
    = New UploadManager
            Typology 
    um.TypologyField
            Set um 
    Nothing
        End Property
        
    End 
    Class

    Class 
    RequestItemFile

        
    Public Info
        
    Public Value
        
        
    Public Property Get Name
            Dim s
    e
            s 
    InStr(Info"name=""") + Len("name=""")
            If 
    InStrRev(Info""";") > 0 Then
                e 
    InStrRev(Info""";") - 1
            
    Else
                
    InStrRev(Info"""") - 1
            End 
    If
            
    Name Mid(Infos1)
        
    End Property
        
        
    Public Property Get Typology
            Dim um
            Set um 
    = New UploadManager
            Typology 
    um.TypologyFile
            Set um 
    Nothing
        End Property
        
        
    Public Property Get FullPath
            Dim s
    e
            s 
    InStr(Info"filename=""") + Len("filename=""")
            
    InStrRev(Info"""" vbCrLf) - 1
            FullPath 
    Replace(Mid(Infos1), "/""\")
        End Property
        
        Public Property Get FileName
            Dim s
            s = InStrRev(FullPath, "
    \") + 1
            FileName = Mid(FullPath, s, Len(FullPath) - s + 1)
        End Property
        
        Public Property Get FileExtension
            Dim s
            s = InStrRev(FileName, "
    .") + 1
            FileExtension = Mid(FileName, s, Len(FileName) - s + 1)
        End Property
            
        Public Property Get FileSize
            FileSize = Len(Value)    ' byte
        End Property
        
        Public Property Get ContentType
            Dim s
            s = InStr(Info, "
    Content-Type") + Len("Content-Type")
            ContentType = Mid(Info, s, Len(Info) - s + 1)
        End Property
        
        Public Function Save(remotepath, remotefilename)
            Dim fn, fso, rpl, cp, i, f
            remotepath = Replace(remotepath, "
    /", "\")
            If Right(remotepath, 1) <> "
    \" Then remotepath = remotepath & "\"
            fn = remotepath & remotefilename
            Set fso = Server.CreateObject("
    Scripting.FileSystemObject")
            ' build remote path
            If Not fso.FolderExists(remotepath) Then
                rpl = Split(remotepath, "
    \")
                cp = rpl(0)
                For i = 1 To UBound(rml)
                    cp = cp & "
    \" & rpl(i)
                    If Not fso.FolderExists(cp) Then fso.CreateFolder(cp)
                Next
            End If
            ' save file
            Set f = fso.OpenTextFile(fn, 2, True)
            f.Write Value
            f.Close
            Set f = Nothing
            Set fso = Nothing
        End Function

    End Class 
    http://www.generationweb.it <--- web site

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.