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

    interfaccia ASP per FileReference (upload)

    un saluto a tutto il FORUM, dopo mesi di assenza!


    Veniamo al dunque...

    PREMESSA
    ho la necessità di implementare in un'applicazione Flash [8] la funzionalità di upload di immagini sul server.

    Per far questo ho visto che c'è la comodissima classe FileReference (flash.net.FileReference), che però non ho mai utilizzato.

    La documentazione è però esauriente e mi pare che non ci siano difficoltà di sorta lato Client (cioè Flash), il problema sta invece nel lato server:

    normalmente io non mi occupo di questa faccia della luna ma stavolta mi tocca.
    Il sito in oggetto supporta ASP di cui conosco solo i rudimenti.

    DOMANDA
    c'è qualcuno che sa come sviluppare in ASP un'interfaccia con la funzionalità FileReference (flash.net.FileReference)
    di Flash [8] ?

  2. #2

  3. #3
    Utente di HTML.it L'avatar di and80
    Registrato dal
    Mar 2003
    Messaggi
    15,182
    allora, ti premetto che non sono pratico di asp e di solito uso php per lo scopo, ma considera comunque che la chiamata ad asp da flash è uguale a quella che farebbe un form in html (apparte le chiamate multiple per verificare il progresso, ma è un'altra cosa)
    perciò se tu utilizzi uno script di upload in asp che sia valido per un form html, questo funzionerà anche per flash
    l'unica cosa di cui devi tener conto è che flash imposta automaticamente il nome del riferimento di upload a "Filedata", mentre in html il nome lo daresti tu.
    ora provo a cercare uno script per l'upload in asp e vediamo di proseguire insieme

  4. #4
    premetto che ho sempre evitato l'upload con filereference e lo provai un pò di tempo fa cmq ho alcuni file asp che fanno questo ad es prova questo..
    questo è il file upload.asp
    Codice PHP:

    <%
        
    'this demo uses modified version of freeASPUpload from [url]http://www.freeaspupload.net[/url]
        Dim Upload, fileName, fileSize, ks, i, fileKey
      Dim uploadsDirVar
        dim objFSO
        
        uploadsDirVar = Server.MapPath(".")
        set objFSO=server.createObject("Scripting.FileSystemObject")
        Set Upload = New FreeASPUpload
      Upload.Save(uploadsDirVar)
        
        '
    delete the file to conserve hard drive space
    '    for each fileKey in Upload.UploadedFiles.keys
    '        
    objFSO.deletefile uploadsDirVar "\" & Upload.UploadedFiles(fileKey).FileName, false
    '    next
    %> 
    mentre il file freeaspupload.asp quello incluso
    Codice PHP:
    <%
    '  For examples, documentation, and your own free copy, go to:
    '  
    [url]http://www.freeaspupload.net[/url]
    '  Note: You can copy and use this script for free and you can make changes
    '  
    to the codebut you cannot remove the above comment.

    'Changes:
    '
    Aug 22005Add support for checkboxes and other input elements with multiple values
    'Mar 7, 2006: Add support for FlashUpload (rizal.firmansyah@masrizal.com)

    Class FreeASPUpload
        Public UploadedFiles
        Public FormElements

        Private VarArrayBinRequest
        Private StreamRequest
        Private uploadedYet

        Private Sub Class_Initialize()
            Set UploadedFiles = Server.CreateObject("Scripting.Dictionary")
            Set FormElements = Server.CreateObject("Scripting.Dictionary")
            Set StreamRequest = Server.CreateObject("ADODB.Stream")
            StreamRequest.Type = 1 '
    adTypeBinary
            StreamRequest
    .Open
            uploadedYet 
    false
        End Sub
        
        
    Private Sub Class_Terminate()
            If 
    IsObject(UploadedFilesThen
                UploadedFiles
    .RemoveAll()
                
    Set UploadedFiles Nothing
            End 
    If
            If 
    IsObject(FormElementsThen
                FormElements
    .RemoveAll()
                
    Set FormElements Nothing
            End 
    If
            
    StreamRequest.Close
            Set StreamRequest 
    Nothing
        End Sub

        
    Public Property Get Form(sIndex)
            
    Form ""
            
    If FormElements.Exists(LCase(sIndex)) Then Form FormElements.Item(LCase(sIndex))
        
    End Property

        
    Public Property Get Files()
            
    Files UploadedFiles.Items
        End Property

        
    'Calls Upload to extract the data from the binary request and then saves the uploaded files
        Public Sub Save(path)
            Dim streamFile, fileItem

            if Right(path, 1) <> "\" then path = path & "\"

            if not uploadedYet then Upload

            For Each fileItem In UploadedFiles.Items
                Set streamFile = Server.CreateObject("ADODB.Stream")
                streamFile.Type = 1
                streamFile.Open
                StreamRequest.Position=fileItem.Start
                StreamRequest.CopyTo streamFile, fileItem.Length
                streamFile.SaveToFile path & fileItem.FileName, 2
                streamFile.close
                Set streamFile = Nothing
                fileItem.Path = path & fileItem.FileName
             Next
        End Sub

        Public Function SaveBinRequest(path) ' 
    For debugging purposes
            StreamRequest
    .SaveToFile path "\debugStream.bin"2
        End 
    Function

        Public 
    Sub DumpData() 'only works if files are plain text
            Dim i, aKeys, f
            response.write "Form Items:
    "
            aKeys = FormElements.Keys
            For i = 0 To FormElements.Count -1 ' 
    Iterate the array
                
    response.write aKeys(i) & " = " FormElements.Item(aKeys(i)) & "
    "
            
    Next
            response
    .write "Uploaded Files:
    "
            
    For Each f In UploadedFiles.Items
                response
    .write "Name: " f.FileName "
    "
                
    response.write "Type: " f.ContentType "
    "
                
    response.write "Start: " f.Start "
    "
                
    response.write "Size: " f.Length "
    "
             
    Next
           End Sub

        
    Private Sub Upload()
            
    Dim nCurPosnDataBoundPosnLastSepPos
            Dim nPosFile
    nPosBound
            Dim sFieldName
    osPathSepauxStr

            
    'RFC1867 Tokens
            Dim vDataSep
            Dim tNewLine, tDoubleQuotes, tTerm, tFilename, tName, tContentDisp, tContentType
            tNewLine = Byte2String(Chr(13))
            tDoubleQuotes = Byte2String(Chr(34))
            tTerm = Byte2String("--")
            tFilename = Byte2String("filename=""")
            tName = Byte2String("name=""")
            tContentDisp = Byte2String("Content-Disposition")
            tContentType = Byte2String("Content-Type:")

            uploadedYet = true

            '
    on error resume next
            VarArrayBinRequest 
    Request.BinaryRead(Request.TotalBytes)
            
    'VarArrayBinRequest=VarArrayBinRequest & tTerm
            
            if Err.Number <> 0 then 
                response.write "

    [B]System reported this error:[/B]

    "
                response.write Err.Description & "

    "
                response.write "The most likely cause for this error is the incorrect setup of AspMaxRequestEntityAllowed in IIS MetaBase. Please see instructions in the [url='
    http://www.freeaspupload.net/freeaspupload/requirements.asp']requirements page of freeaspupload.net[/url].

    "
                Exit Sub
            end if
            on error goto 0 'reset error handling

            nCurPos = FindToken(tNewLine,1) 'Note: nCurPos is 1-based (and so is InstrB, MidB, etc)

            If nCurPos <= 1  Then Exit Sub
             
            'vDataSep is a separator like -----------------------------21763138716045
            vDataSep = MidB(VarArrayBinRequest, 1, nCurPos-1)
            
            'Start of current separator
            nDataBoundPos = 1

            'Beginning of last line
            'nLastSepPos = FindToken(vDataSep & tTerm, 1)
            'if nLastSepPos=0 then
            'if chr(ascb(midb(VarArrayBinRequest,lenb(VarArrayBinRequest),1)))=tnewline then
            '    nLastSepPos=lenb(VarArrayBinRequest)-lenb(vDataSep)-4+1
            'else
                nLastSepPos=lenb(VarArrayBinRequest)-lenb(vDataSep)+1
            'end if
            
            Do Until nDataBoundPos = nLastSepPos
                
                nCurPos = SkipToken(tContentDisp, nDataBoundPos)
                nCurPos = SkipToken(tName, nCurPos)
                sFieldName = ExtractField(tDoubleQuotes, nCurPos)

                nPosFile = FindToken(tFilename, nCurPos)
                nPosBound = FindToken(vDataSep, nCurPos)
                
                If nPosFile <> 0 And  nPosFile < nPosBound Then
                    Dim oUploadFile
                    Set oUploadFile = New UploadedFile
                    
                    nCurPos = SkipToken(tFilename, nCurPos)
                    auxStr = ExtractField(tDoubleQuotes, nCurPos)
                    ' We are interested only in the name of the file, not the whole path
                    ' Path separator is \ in windows, / in UNIX
                    ' While IE seems to put the whole pathname in the stream, Mozilla seem to 
                    ' only put the actual file name, so UNIX paths may be rare. But not impossible.
                    osPathSep = "
    \"
                    if InStr(auxStr, osPathSep) = 0 then osPathSep = "
    /"
                    oUploadFile.FileName = Right(auxStr, Len(auxStr)-InStrRev(auxStr, osPathSep))

                    if (Len(oUploadFile.FileName) > 0) then 'File field not left empty
                        nCurPos = SkipToken(tContentType, nCurPos)
                        
                        auxStr = ExtractField(tNewLine, nCurPos)
                        ' NN on UNIX puts things like this in the streaa:
                        '    ?? python py type=?? python application/x-python
                        oUploadFile.ContentType = Right(auxStr, Len(auxStr)-InStrRev(auxStr, " "))
                        nCurPos = FindToken(tNewLine, nCurPos) + 4 'skip empty line
                        
                        oUploadFile.Start = nCurPos-1
                        oUploadFile.Length = FindToken(vDataSep, nCurPos) - 2 - nCurPos
                        
                        If oUploadFile.Length > 0 Then UploadedFiles.Add LCase(sFieldName), oUploadFile
                    End If
                Else
                    Dim nEndOfData
                    nCurPos = FindToken(tNewLine, nCurPos) + 4 'skip empty line
                    nEndOfData = FindToken(vDataSep, nCurPos) - 2
                    If Not FormElements.Exists(LCase(sFieldName)) Then 
                        FormElements.Add LCase(sFieldName), String2Byte(MidB(VarArrayBinRequest, nCurPos, nEndOfData-nCurPos))
                    else
                        FormElements.Item(LCase(sFieldName))= FormElements.Item(LCase(sFieldName)) & "
    " & String2Byte(MidB(VarArrayBinRequest, nCurPos, nEndOfData-nCurPos)) 
                    end if 

                End If

                'Advance to next separator
                nDataBoundPos = FindToken(vDataSep, nCurPos)
            Loop
            StreamRequest.Write(VarArrayBinRequest)
        End Sub

        Private Function SkipToken(sToken, nStart)
            SkipToken = InstrB(nStart, VarArrayBinRequest, sToken)
            If SkipToken = 0 then
                Response.write "
    Error in parsing uploaded binary request."
                Response.End
            end if
            SkipToken = SkipToken + LenB(sToken)
        End Function

        Private Function FindToken(sToken, nStart)
            FindToken = InstrB(nStart, VarArrayBinRequest, sToken)
        End Function

        Private Function ExtractField(sToken, nStart)
            Dim nEnd
            nEnd = InstrB(nStart, VarArrayBinRequest, sToken)
            If nEnd = 0 then
                Response.write "
    Error in parsing uploaded binary request."
                Response.End
            end if
            ExtractField = String2Byte(MidB(VarArrayBinRequest, nStart, nEnd-nStart))
        End Function

        'String to byte string conversion
        Private Function Byte2String(sString)
            Dim i
            For i = 1 to Len(sString)
               Byte2String = Byte2String & ChrB(AscB(Mid(sString,i,1)))
            Next
        End Function

        'Byte string to string conversion
        Private Function String2Byte(bsString)
            Dim i
            String2Byte =""
            For i = 1 to LenB(bsString)
               String2Byte = String2Byte & Chr(AscB(MidB(bsString,i,1))) 
            Next
        End Function
    End Class

    Class UploadedFile
        Public ContentType
        Public Start
        Public Length
        Public Path
        Private nameOfFile

        ' Need to remove characters that are valid in UNIX, but not in Windows
        Public Property Let FileName(fN)
            nameOfFile = fN
            nameOfFile = SubstNoReg(nameOfFile, "
    \", "_")
            nameOfFile = SubstNoReg(nameOfFile, "
    /", "_")
            nameOfFile = SubstNoReg(nameOfFile, "
    :", "_")
            nameOfFile = SubstNoReg(nameOfFile, "
    *", "_")
            nameOfFile = SubstNoReg(nameOfFile, "
    ?", "_")
            nameOfFile = SubstNoReg(nameOfFile, """", "
    _")
            nameOfFile = SubstNoReg(nameOfFile, "
    <", "_")
            nameOfFile = SubstNoReg(nameOfFile, "
    >", "_")
            nameOfFile = SubstNoReg(nameOfFile, "
    |", "_")
        End Property

        Public Property Get FileName()
            FileName = nameOfFile
        End Property

        'Public Property Get FileN()ame
    End Class


    ' Does not depend on RegEx, which is not available on older VBScript
    ' Is not recursive, which means it will not run out of stack space
    Function SubstNoReg(initialStr, oldStr, newStr)
        Dim currentPos, oldStrPos, skip
        If IsNull(initialStr) Or Len(initialStr) = 0 Then
            SubstNoReg = ""
        ElseIf IsNull(oldStr) Or Len(oldStr) = 0 Then
            SubstNoReg = initialStr
        Else
            If IsNull(newStr) Then newStr = ""
            currentPos = 1
            oldStrPos = 0
            SubstNoReg = ""
            skip = Len(oldStr)
            Do While currentPos <= Len(initialStr)
                oldStrPos = InStr(currentPos, initialStr, oldStr)
                If oldStrPos = 0 Then
                    SubstNoReg = SubstNoReg & Mid(initialStr, currentPos, Len(initialStr) - currentPos + 1)
                    currentPos = Len(initialStr) + 1
                Else
                    SubstNoReg = SubstNoReg & Mid(initialStr, currentPos, oldStrPos - currentPos) & newStr
                    currentPos = oldStrPos + skip
                End If
            Loop
        End If
    End Function
    %> 
    la verità non è una meretrice che si getta al collo di chi non la vuole ma anzi essa è dotata di una così altera bellezza che anche chi sacrifica tutto per ottenerla non è sicuro di averla raggiunta !

  5. #5
    Grazie per il supporto ragazzi!
    Stasera provo a mettere in pratica i vs. consigli!

    ciao!

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 © 2026 vBulletin Solutions, Inc. All rights reserved.