Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save itowhid06/46ccc16dc045f967a194c1e341656ef8 to your computer and use it in GitHub Desktop.
Save itowhid06/46ccc16dc045f967a194c1e341656ef8 to your computer and use it in GitHub Desktop.
Save canvas Data with jQuery and PHP
The following code saves a canvas as png with ajax to php.
Javascript:
var canvasData = canvasElement.toDataURL("image/png");
$.ajax({
url:'save.php',
type:'POST',
data:{
data:canvasData
}
});
PHP:
$data = $_POST['data'];
$data = substr($data,strpos($data,",")+1);
$data = base64_decode($data);
$file = 'output.png';
file_put_contents($file, $data);
echo "Success!";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment