I'm using an ajax query to upload canvas image data, along with a few other variables. Here's what the relevant code looks like on the client side:
front_content = document.getElementById("front_paint_canvas").toDataURL("image/png");
ajaxHandler.open("POST", "upload_card", true);
ajaxHandler.setRequestHeader("Content-type","application/x-www-form-urlencoded");
ajaxHandler.send("name="+name+"&front_content="+front_content);
And here's what I have on the server side:
$front_content = substr($_POST['front_content'], strpos($_POST['front_content'], ",")+1);
$decodedData=base64_decode($front_content);
$fp = fopen( getcwd().'/assets/img/canvas.png', 'wb' );
fwrite( $fp, $decodedData);
fclose( $fp );
This creates a file that appears to be the right size, and is also of the right dimensions. However, the file is blank. None of the image data that was in the canvas shows up. What's being done wrong here?