Here's a worked example. Hard to tell quite where your problem lies with the code you've omitted. In the second snippet for instance, we can't tell if canvas
is valid.
php code: (postExample.php)
<?php
//postExample.php
printf("<img src='%s'/>", $_POST['InsidePhoto']);
?>
html code
<!doctype html>
<html>
<head>
<script>
"use strict";
function newEl(tag){return document.createElement(tag)}
function byId(id){return document.getElementById(id)}
function ajaxPostFormData(url, formData, onSuccess, onError)
{
var ajax = new XMLHttpRequest();
ajax.onload = function(){onSuccess(this);}
ajax.onerror = function(){onError(this);}
ajax.open("POST",url,true);
ajax.send(formData);
}
window.addEventListener('load', onDocLoaded, false);
function onDocLoaded(evt)
{
byId('imgInput').addEventListener('change', onFileInputChanged, false);
}
function onFileInputChanged(evt)
{
var can = byId('preview'), ctx = can.getContext('2d');
var img = new Image();
img.onload = function()
{
can.width = img.width;
can.height = img.height;
ctx.drawImage(img,0,0);
var fd = new FormData();
var canvasData = can.toDataURL("image/png");
fd.append("InsidePhoto", canvasData);
ajaxPostFormData('postExample.php', fd, onSuccess, onError)
}
var dataSrc = URL.createObjectURL(this.files[0]);
img.src = dataSrc;
function onSuccess(ajax)
{
console.log(ajax.response);
var div = newEl('div');
div.innerHTML = ajax.response;
document.body.appendChild( div.childNodes[0] );
}
function onError(ajax)
{
console.log(ajax.response);
}
}
</script>
<style>
</style>
</head>
<body>
<input type='file' id='imgInput'/>
<canvas id='preview'></canvas>
</body>
</html>