J4X
J4X

Reputation: 119

passing canvas image to php

I'm going to upload the canvas image into MYSQL. By using php, but before that, how can I pass the canvasData to php. I've done some searching, but some of the solution are complicated for me. That's why I decide to post a question on here. I'm doing in a localhost environment.

There is a capture button when click on it, will activate this function. It will capture the canvas photo.

function()
{       context.drawImage(video, 0, 0, 300, 200);
        var canvasData = canvas.toDataURL("image/png");
}

as I know right now the canvasData variable will be base64 code.

What is the best solution for me to pass this data to php for me to upload to my database. Thank You in advance.

Upvotes: 1

Views: 1527

Answers (1)

Nik Terentyev
Nik Terentyev

Reputation: 2310

js side:

context.drawImage(video, 0, 0, 300, 200);
var canvasData = canvas.toDataURL("image/png"),
    xhr = new XMLHttpRequest();

xhr.open('POST', url, true);

xhr.onload = function() {
    alert('hooray! uploaded.');
}
xhr.send(canvasData);

php side example you can take here get image from base64 string

Upvotes: 1

Related Questions