Visualizzazione dei risultati da 1 a 2 su 2

Discussione: salvare file su server

  1. #1
    Utente di HTML.it
    Registrato dal
    Jul 2007
    Messaggi
    82

    salvare file su server

    Salve a tutti,
    purtroppo non conosco il linguaggio php, mi serve una mano per scrivere una riga di codice

    codice:
    function CanvasSaver(url) {
         
        this.url = url;
         
        this.savePNG = function(cnvs, fname) {
            if(!cnvs || !url) return;
            fname = fname || 'picture';
             
            var data = cnvs.toDataURL("image/png");
            data = data.substr(data.indexOf(',') + 1).toString();
             
            var dataInput = document.createElement("input") ;
            dataInput.setAttribute("name", 'imgdata') ;
            dataInput.setAttribute("value", data);
             
            var nameInput = document.createElement("input") ;
            nameInput.setAttribute("name", 'name') ;
            nameInput.setAttribute("value", fname + '.png');
             
            var myForm = document.createElement("form");
            myForm.method = 'post';
            myForm.action = url;
            myForm.appendChild(dataInput);
            myForm.appendChild(nameInput);
             
            document.body.appendChild(myForm) ;
            myForm.submit() ;
            document.body.removeChild(myForm) ;
        };
    }
    
    //
    var cs = new CanvasSaver('http://server.php')
    cs.savePNG(cnvs, 'myimage');
    //
    passo al server il file e il nome del file

    codice:
    <?php
        # we are a PNG image
        header('Content-type: image/png');
         
        # we are an attachment (eg download), and we have a name
        header('Content-Disposition: attachment; filename="' . $_POST['name'] .'"');
         
        #capture, replace any spaces w/ plusses, and decode
        $encoded = $_POST['imgdata'];
        $encoded = str_replace(' ', '+', $encoded);
        $decoded = base64_decode($encoded);
         
        #write decoded data
        echo $decoded;
    ?>
    dovrei riuscire a salvare il file nel path C:\ (del server) come faccio? grazie

  2. #2
    Utente di HTML.it L'avatar di Ironmax
    Registrato dal
    Dec 2008
    Messaggi
    1,026
    Inizia a studiare la guida di base che trovi sempre su questo sito:
    http://php.html.it/guide/leggi/99/guida-php-di-base/

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.