1

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.

2
  • 2
    maybe you can use the .toDataURL() method of the canvas. Commented Aug 17, 2015 at 8:35
  • 2
    (1) convert the canvas content to a base64 encoded string using .toDataURL, (2) transmit that string to a .php script on your server with AJAX -- jQuery does this well, (3) create a parametized MySQL statement to store the encoded string to your database. Your question has been asked + answered many times on Stackoverflow. Here's one example post: stackoverflow.com/questions/24575090/…. You can add the form data to your AJAX data packet and have your php store them with the canvas dataUrl. Commented Aug 17, 2015 at 21:03

2 Answers 2

3

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.

Sign up to request clarification or add additional context in comments.

Comments

0

Use base64_encode for create text in MySQL database.

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.