0

I'm trying to use JSC3D to render avatars for my website, like if they change the appearance it re-renders and uploads to server, etc, etc.

Most likely I can figure that out, however I cannot get it to send the data to the php script, I receive no errors or anything (except a couple of javascript errors because I was messing in jsc3d code to prevent it from allowing mouse control)

Ajax/JavaScript:

function saveImage() {
var canvas = document.getElementById("cv");
var canvasData = canvas.toDataURL("image/png");
var xmlHttpReq = true;       
if (window.XMLHttpRequest) {
    ajax = new XMLHttpRequest();
}

else if (window.ActiveXObject) {
    ajax = new ActiveXObject("Microsoft.XMLHTTP");
}
ajax.open('POST', 'hidden.php', true);
ajax.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
ajax.onreadystatechange = function() {
    console.log(ajax.responseText);
}
ajax.send("imgData="+canvasData);
}

PHP:

<?php
if (isset($GLOBALS["HTTP_RAW_POST_DATA"])) {
$imageData=$GLOBALS['HTTP_RAW_POST_DATA'];
$filteredData=substr($imageData, strpos($imageData, ",")+1);
$unencodedData=base64_decode($filteredData);
$fp = fopen('test.png', 'wb' );
fwrite( $fp, $unencodedData);
fclose( $fp );
}
?>

I'm not sure if its broken or not, as I get no errors.. nor does it create the test.png file.

Any help is appreciated!

Amicon Interactive
  • 123
  • 1
  • 1
  • 5
  • I guess second answer will help! http://stackoverflow.com/questions/13198131/how-to-save-a-html5-canvas-as-image-on-a-server – Rayon Mar 11 '16 at 07:29
  • Or http://j-query.blogspot.in/2011/02/save-base64-encoded-canvas-image-to-png.html – Rayon Mar 11 '16 at 07:30

0 Answers0