Error Saving Image in Directory - PHP/JAVASCRIPT

Asked

Viewed 224 times

0

Hello, I’m trying to finish a part of a system, where the user draws his signature and after the action, the Canvas Image is sent to the directory, but when I open the Saved image appears the following error: The image "https://br918.hostgator.com.br:2083/cpsess0222983772/view/home1%2fdsenv18%2pagina.life%2TESTE%2fpagina%2fimg/signature.png" Cannot be displayed bacause it contains error.

Could one of you help me?

PHP

$data = substr($_POST['imageData'], strpos($_POST['imageData'], ",") + 1);
$decodedData = base64_decode($data);

$fp = fopen("img/assinatura.png", 'wb');

fwrite($fp, $decodedData);
fclose($fp);

JAVASCRIPT

<script>
    function salvarImagem(a){ 

    var meucanvas = document.getElementById('newSignature');

    var arquivo = document.getElementById('arquivo');

    /*Comentário: a variavel "a" será o nome do arquivo, use aspas para chamar a função */
    arquivo.download = a;
    arquivo.href = meucanvas.toDataURL();

    function signatureSave(url, name, fn, canvas, type) {

        var data = document.getElementById("assinatura.png").toDataURL();    
        $.post("assinatura.png", {
            imageData : data
        }, function(data) {
            alert('imagem salva');
        });
    }

  • meucanvas.toDataURL("image/png"). replace("image/png", "image/octet-stream");

  • Where is arquivo.href = meucanvas.toDataURL(); do arquivo.href =meucanvas.toDataURL("image/png").replace("image/png", "image/octet-stream");

  • Thanks for the comment Augusto, I changed the line of code DE: file.href = meucanvas.toDataURL(); POR: file.href = meucanvas.toDataURL("image/png"). replace("image/png", "image/octet-stream"); :(

  • Too bad, I’ll do more research if I find something to help you.

  • Thanks for the help Augusto, I’ll keep trying to solve, thanks for your time.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.