Skip to content Skip to sidebar Skip to footer

How Do I Pass The Image Created By Todataurl.js To Mysql?

I have a script that captures a signature via touch screen or mouse pad and I want to take that image that the todataurl.js creates and upload it to a folder on my server so I can

Solution 1:

.toDataURL() creates a string from your canvas image, I'm guessing this is sent to your server to save it by that javascript. Are you processing this to save your image on the server?

The string sent starts with something like

data:image/png;base64,

followed by the actual image converted to Base 64.

  • Update

Sending the image string to your server:

$.ajax({
  type: "POST",
  url: "script.php",
  data: { 
     imageString: canvas.toDataURL("image/png");
  },
  success: function(response){ alert("image sent"); },
  error: function(xhr, status, error){ alert("there was an error sending the image" + error); },
});

You can put this in your signatureSave() function. On server side, in script.php you can simply grab the string with $_POST['imageString'], remove the identifying part from it (data:image/png;base64,) and Base64 decode the rest of the string then save it.

$image= imagecreatefromstring(base64_decode(str_replace("data:image/png;base64,", "", $_POST['imageData])));
imagepng("path/to/save/yourimage.png");

Post a Comment for "How Do I Pass The Image Created By Todataurl.js To Mysql?"