Created
May 14, 2018 12:04
-
-
Save itowhid06/46ccc16dc045f967a194c1e341656ef8 to your computer and use it in GitHub Desktop.
Save canvas Data with jQuery and PHP
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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