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!