Marko Adam
Marko Adam

Reputation: 107

How to input image from canvas to MySql database?

I have an image in canvas but want to upload it to database. I have no problem with upload when it's classical (trough <input type='file'>).

I know how to download it from canvas, but have problem with upload from it.

Also, after fooling around with image in canvas, some form should be filled.

Nothing special it's for, some marketing campaign, where you upload photo, put some filters and frames, than upload it.

Upvotes: 1

Views: 2337

Answers (2)

Ponpon32
Ponpon32

Reputation: 2200

You can get base64 image encoded and save it to database.

var canvas = document.getElementById("canvasObj");
var pngUrl = canvas.toDataURL(); // PNG is the default

Code taken from here, you should read it first.

Upvotes: 3

Knase
Knase

Reputation: 1274

Use base64_encode for create text in MySQL database.

$image = file_get_contents('filename.gif');
$imageText = base64_encode($image);     

Upvotes: 0

Related Questions