Answer the question
In order to leave comments, you need to log in
Upload image from canvas to server?
Hello. Please tell me how to transfer images from canvas to server. Interested in exactly the moment, how to get a file to send? Thank you.
Answer the question
In order to leave comments, you need to log in
var canvas = document.getElementById('myCanvas');
var dataURL = canvas.toDataURL();
$.ajax({
type: "POST",
url: "script.php",
data: {
imgBase64: dataURL
}
});
$img = $_POST['imgBase64'];
$img = str_replace('data:image/png;base64,', '', $img);
$img = str_replace(' ', '+', $img);
$fileData = base64_decode($img);
$fileName = 'photo.png';
file_put_contents($fileName, $fileData);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question