Pagina 1 di 2 1 2 ultimoultimo
Visualizzazione dei risultati da 1 a 10 su 12
  1. #1

    wbresize prima dell'upload dell'immagine

    Salve, ho trovato un codice per effettuare l'upload delle immagini.

    Mi rimane comodo per il fatto che questa finestra viene aperta in popup, viene caricata l'immagine ed uploadata ed infine il nome dell'immagine viene inserito in un campo del form nella pagina principale.

    Tutto ok, funziona bene, ma volevo poter effettuare il ridimensionamento dell'immagine tramite il wbresize di imente, prima che l'immagine venisse caricata sul server, ma non ho idea di come fare!!!


    (Arriva la sfilza di codice!)
    Codice PHP:
    <%
    'Encode JavaScript strings
    Function jsEncode(text)
        jsEncode = Replace(text, "\", "\\")
        jsEncode = Replace(jsEncode, "'", "
    \'")
    End Function

    '
    Convert a String to Binary
    Function string2bin(String)
        
    Dim IB
        
    For I=1 to len(String)
            
    ChrB(Asc(Mid(String,I,1)))
        
    Next
        string2bin 
    B
    End 
    Function

    'Convert a Binary to String
    Function bin2string(bin)
        For i = 1 To lenB(bin)
            bin2string  = bin2string  & chr(ascB(midB(bin, i, 1)))
        Next
    End Function

    This function converts multibyte string to real binary data (VT_UI1 VT_ARRAY)
    Function 
    bin2array(bin)
        
    Dim RSLMultiByteBinary
        
    Const adLongVarBinary 205
        
    ' Using recordset
        Set RS = CreateObject("ADODB.Recordset")
        LMultiByte = LenB(bin)
        if LMultiByte>0 then
            RS.Fields.Append "mBinary", adLongVarBinary, LMultiByte
            RS.Open
            RS.AddNew
            RS("mBinary").AppendChunk bin & ChrB(0)
            RS.Update
            Binary = RS("mBinary").GetChunk(LMultiByte)
        End If
        bin2array = Binary
    End Function

    Server.ScriptTimeout = 600    '
    10 minutes
    'Read data
    ReceivedBytes = Request.TotalBytes
    If ReceivedBytes > 0 Then
        
        ChunkReadSize =  32768    '
    Max 32 KB
        
        
        
    If ReceivedBytes ChunkReadSize Then
        Response
    .Write("<font face='Verdana' size='2'>Errore: Immagine troppo grande.
    [url='javascript:history.back()']Riprova[/url] con una di dimensione inferiore a 32KB</font><font color='#FFFFFF'>"
    )

        
    End If
        
        
    BytesRead 0
        Set DataStream 
    createobject("ADODB.Stream")
        
    DataStream.Open
        DataStream
    .Type 'Binary
        Do While BytesRead < ReceivedBytes
            '
    Read chunk of data
            PartSize 
    ChunkReadSize
            
    if PartSize BytesRead ReceivedBytes Then PartSize ReceivedBytes BytesRead
            DataPart 
    Request.BinaryRead(PartSize)
            
    BytesRead BytesRead PartSize
            DataStream
    .Write DataPart
        Loop
        DataStream
    .Position 0
        ReceivedData 
    DataStream.Read
        Set DataStream 
    Nothing
        Upload 
    False
        Boundary 
    MidB(ReceivedData1InstrB(ReceivedDatastring2bin("" vbCrLf)) - 1)
        
    pos InstrB(ReceivedDatastring2bin("" vbCrLf)) + len("" vbCrLf)

        
    lenCrLf Len("" vbCrLf)

        Do While 
    pos ReceivedBytes
            StartPos 
    InstrB(posReceivedDatastring2bin("" vbCrLf "" vbCrLf))
            If 
    StartPos pos lenCrLf lenCrLf <= 0 Then
                
    Exit Do
            
    End If
            
    Header bin2string(MidB(ReceivedDataposStartPos pos lenCrLf lenCrLf))
            
    pos InstrB(posReceivedDataBoundary) - 1
            StartPos 
    StartPos lenCrLf lenCrLf
            FileContent 
    MidB(ReceivedDataStartPospos StartPos lenCrLf 1)
            
    pos pos LenB(Boundary)

            
    ' Get the fields if they are compiled
            if instr(Header, "field") > 0 then
                field = bin2string(FileContent)
            end if
            if instr(Header, "path") > 0 then
                path = bin2string(FileContent)
            end if
            if instr(Header, "prev") > 0 then
                prev = bin2string(FileContent)
            end if
            if instr(Header, "thumbField") > 0 then
                thumbField = bin2string(FileContent)
            end if
            if instr(Header, "thumbPath") > 0 then
                thumbPath = bin2string(FileContent)
            end if
            if instr(Header, "thumbWidth") > 0 then
                thumbWidth = bin2string(FileContent)
            end if
            if instr(Header, "thumbHeight") > 0 then
                thumbHeight = bin2string(FileContent)
            end if
            if instr(Header, "imgWidth") > 0 then
                imgWidth = bin2string(FileContent)
            end if
            if instr(Header, "imgHeight") > 0 then
                imgHeight = bin2string(FileContent)
            end if

            ' 
    Get the file to upload (if present) and write it to the server
            
    If Instr(Header"upload") > 0 then
                i 
    Instr(Header"filename=")
                
    Instr(10Headerchr(34))
                
    UploadName mid(Header1010)
                
    instrRev(UploadName"\")
                If i <> 0 then
                    FileName = mid(UploadName, i + 1)
                Else
                    FileName = UploadName
                End If
                If FileName <> "" then
                    Set binaryStream = createobject("
    ADODB.Stream")
                    Set FSO = CreateObject("
    Scripting.FileSystemObject")
                    Upload = true
                    j = InStrRev(FileName, "
    .")
                    FileNameWithoutExtension = left(FileName, j - 1)
                    Extension = right(FileName, Len(FileName) - j + 1)
                    If FileName <> prev Then
                        j = 1
                        Do While FSO.FileExists(path & "
    /" & FileName)
                            FileName = FileNameWithoutExtension & j & Extension
                            j = j + 1
                        Loop
                        If j > 1 Then
                            FileNameWithoutExtension = FileNameWithoutExtension & (j - 1)
                        End If
                    End If
                    binaryStream.Type = 1 'Binary
                    binaryStream.Open
                    if lenb(FileContent) > 0 then binaryStream.Write bin2array(FileContent)
                    binaryStream.SaveToFile path & "
    /" & FileName, 2 'Overwrite
                    'If CInt(thumbWidth) > 0 Then
                        'I must create the thumbnail
                        'ResizeImage path & "
    /" & FileName, thumbPath & "/" & FileNameWithoutExtension & ".jpg", "JPG", CInt(thumbWidth), CInt(thumbHeight)
                        'ThumbFile = FileNameWithoutExtension & "
    .jpg"
                    'End If
                    'If CInt(imgWidth) > 0 Then
                        'I must resize the original image
                    '    ResizeImage path & "
    /" & FileName, path & "/" & FileNameWithoutExtension & ".jpg", "JPG", CInt(imgWidth), CInt(imgHeight)
                    '    If LCase(Extension) <> "
    .jpg" Then
                            'Delete the original file
                    '        FSO.DeleteFile path & "
    /" & FileName
                    '    End If
                        FileName = FileNameWithoutExtension & "
    .jpg"
                    End If
                    Set binaryStream = Nothing
                    Set FSO = Nothing
                End If
            'End If
        Loop

        If Upload = True Then
    %>
    <html>
    <head>
        <title>Upload</title>
        <meta name="
    author" content="Danilo Cicognani" />
        <meta name="
    robots" content="noindex,nofollow"/>
        <script language="
    javascript">
            window.opener.document.<%= field %>.value = '<%= jsEncode(FileName) %>';
            <% If CInt(thumbWidth) > 0 Then %>
            window.opener.document.<%= thumbField %>.value = '<%= jsEncode(ThumbFile) %>';
            <% End If %>
            window.close();
        </script>
    </head>
    <body background="
    img/stripe_b.gif">
    </body>
    </html>
    <%
        End If
    Else
        field = Request("
    field")
        path = Request("
    path")
        prev = Request("
    prev")
        thumbField = Request("
    thumbField")
        thumbPath = Request("
    thumbPath")
        thumbWidth = Request("
    thumbWidth")
        thumbHeight = Request("
    thumbHeight")
        imgWidth = Request("
    imgWidth")
        imgHeight = Request("
    imgHeight")
    End If

    If Upload = False then
    %>
    <html>
    <head>
        <title>Upload</title>
    </head>
    <body background="
    img/stripe_b.gif">
        <h1><font face="
    Verdana" size="4" color="#FE6001">Caricamento immagine</font></h1>
        
    <form name="upload" action="upload.asp" method="post" enctype="multipart/form-data">
            <
    input type="hidden" name="field" value="<%= field %>"/>
            <
    input type="text" name="path" value="<%= path %>" size="20"/>
            <
    input type="hidden" name="prev" value="<%= prev %>"/>
            <
    input type="hidden" name="thumbField" value="<%= thumbField %>"/>
            <
    input type="hidden" name="thumbPath" value="<%= thumbPath %>"/>
            <
    input type="hidden" name="thumbWidth" value="<%= thumbWidth %>"/>
            <
    input type="hidden" name="thumbHeight" value="<%= thumbHeight %>"/>
            <
    input type="hidden" name="imgWidth" value="<%= imgWidth %>" size="20"/>
            <
    input type="hidden" name="imgHeight" value="<%= imgHeight %>" size="20"/>
            <
    input type="file" name="upload" size="20"/>
            <
    input type="submit" name="submit" value="Invia"/>
        </
    form>
        
        
        <
    form name="upload2" action="wbresize.aspx?f=<%=img%><%= path %>&c=100&h=90&t=public/thumbs&n=thumb&r=ok.asp&e=error.asp?c=" method="post" enctype="multipart/form-data">
        <
    input type="file" name="upload2" size="20"/>
        <
    input type="submit" name="submit" value="Invia"/>    </form>
        
        <
    font face="Verdana" size="2">
        [
    url="wbresize.aspx?f=<%= upload %>&c=100&h=90&t=public/thumbs&n=thumb&r=ok.asp&e=error.asp?c="]ridimensiona[/url]</font>
        

    <
    font face="Verdana" size="2">La grandezza massima dell'immagine non può superare i 
        [b]32 KB[/b]</font></br>
        <font face="Verdana" size="2">Immagini supportate: jpg - jpeg - gif - bmp - png</font></p>
        </body>
    </html>
    <%
    End If
    %> 

    PS: La parte del form funzionante è al primo "Invia" dove viene uploadata l'immagine.
    Le altre due sezioni a seguire non funzionano (anche perchè non viene inviato il nome dell'immagine)

  2. #2
    Utente di HTML.it L'avatar di agenti
    Registrato dal
    Feb 2002
    Messaggi
    2,427
    il salvataggio di imente se non sbaglio ha bisogno di un file sul server per il resize

    quindi fai l'upload lo tratti come un file temporaneo e dopo lo cancelli.

  3. #3
    Si utilizza il file wbresize.aspx che fa il resize dell'immagine. Il fatto pche non so come fare questo passaggio.

  4. #4
    Utente di HTML.it L'avatar di agenti
    Registrato dal
    Feb 2002
    Messaggi
    2,427
    turista fai date ?
    non html.it ???

    ahi ahi ahi ahi.....

    guarda dentro il file webresize e trovi spiegato il tutto...
    ridimensiona

  5. #5
    >_>


    Veramente questa parte è già presente nel codiche che ho inserito il fatto è comunque quello di inviare l'immagine prima al wbresize e poi farla caricare, tutto in automatico ed in un unico passaggio per l'utente finale.

  6. #6
    Utente di HTML.it L'avatar di agenti
    Registrato dal
    Feb 2002
    Messaggi
    2,427
    come ti dicevo non puoi farlo...
    prima fai l'upload e poi lo sottoponi al webresize.
    Asp non consente la gestione di file temporanei.

    forse tramite un componente puoi farlo ma non con una classe.

  7. #7
    Qual'è secondo te il modo migliore per farlo fa "inconsapevolmente" all'utente?
    Visto che è improbabile che mi clicchi su ridimensiona, giustamente.

  8. #8
    Originariamente inviato da Psycho Mantys
    Qual'è secondo te il modo migliore per farlo fa "inconsapevolmente" all'utente?
    Visto che è improbabile che mi clicchi su ridimensiona, giustamente.
    ma che vuol dire? tu fai l'upload per forza perchè finchè l'upload non è completato non parte l'asp che poi salva il file nella cartella dove vuoi.. tu devi

    1) parcheggiare il file in una tua cartella temporanea (se proprio non vuoi usare quella dell'utente)

    2) richiamare wbresize via xmlhttp

    3) spostare il file ridimensionato nel punto giusto (mi pare che puoi farlo direttamente con wbresize)

    4) dire all'utente "tutto fatto dormi sonni tranquilli"

    IP-PBX management: http://www.easypbx.it

    Old account: 2126 messages
    Oldest account: 3559 messages

  9. #9
    Ok, sembra che wbresize faccia l'upload dell'anteprima, quindi sfruttando questa caratteristica, dovrebbe andar bene il seguente codice che mi dovrebbe salvare l'anteprima dentro la cartella public\cover:


    Codice PHP:
    <%
    immagine=Request.Form("immagine")
    %>

    <
    form name="upload" action="upload2.asp" method="post">
    <
    input type="file" name="immagine" size="20"/>
    <
    input type="submit" name="submit" value="Invia"/>
    </
    form>
        


    [
    url="wbresize.aspx?f=<%=immagine%>&c=100&h=90&t=public/cover&n=thumb&r=upload.asp&e=error.asp?c="]ridimensiona[/url
    Tuttavia cliccando su ridimensiona mi esce un errore 99 che stando al codice potrebbe essere per una questione di permessi, anche se la cartella public ha i permessi di scrittura (è su server Aruba).

  10. #10
    non so la versione nuova di wbresize, ma questo codice

    ridimensiona

    non capisco a cosa ti serva? "immagine" come lo inizializzi scusa?
    IP-PBX management: http://www.easypbx.it

    Old account: 2126 messages
    Oldest account: 3559 messages

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.