Canvas.toDataUrl when I decode the image
<p>I'm working with canvas for a CMS that we are doing in my job. The problem that I have is when I get the base64 of the image of the canvas, then I decode the image in the server with base64_decode (php) but when I show the image in the HTML file firebug shows this error:"Image corrupt or truncated", this is a piece of the base64 string: data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAA7YAAAFe....
Has someone any idea of what I doing wrong?</p>

<p>Thanks a lot to everybody.</p>

<p>This is the javascript code:</p>

<pre><code>function(oCanvas, bReturnImg, iWidth, iHeight) {
            if (!bHasDataURL) {
                return false;
            }
            var oScaledCanvas = scaleCanvas(oCanvas, iWidth, iHeight);
            var strData = oScaledCanvas.toDataURL("image/png");
            if (bReturnImg) {
                return makeImageObject(strData);               
            } else {
                /*HACER LLAMADA A AJAX PARA GUARDAR LA IMAGEN EN BASE64 EN MONGO*/
                $.ajax({
                    url:'/demo_banners/web/app_dev.php/savecanvas',
                    data:'str='+strData,
                    type:'POST',
                    success: function(data){
                        alert(base64_decode(data));
                            $('#controles').append('&lt;img src="'+base64_decode(data)+'" &gt;');
                    }

                });
                //saveFile(strData.replace("image/png", strDownloadMime));
            }
            return true;
        },
</code></pre>

<p>And this is the PHP code:</p>

<pre><code>public function savebase64Action() {

        $dm = $this-&gt;get('doctrine.odm.mongodb.document_manager');        
        $cod_img = $this-&gt;getRequest()-&gt;get('str');
        $tokens=explode(',',$cod_img);
        //$imagen = $dm-&gt;getRepository('BannerBundle:Imagen')-&gt;find('4fce20cd4ee65c6404000008');

        $bytes = base64_decode($tokens[1]);

        //$bytes = $imagen-&gt;getFile()-&gt;getBytes();

        $file = new GridFSFile();
        $file-&gt;setBytes($bytes);

        $img = new Imagen();
        $img-&gt;setFile($file);
        //$img-&gt;setUploadDate($uploadDate);

        $dm-&gt;persist($img);
        $dm-&gt;flush();

    }
</code></pre>
