php - How to Save and retrieve HTML 5 canvas (Fabric.js) into MySQL blob -


i want save , retrieve html 5 canvas have drawn using fabric.js, javascript library, mysql table using php has field namely cnvs_obj of blob type. have seen lot of tuts , q/a sessions none has step step way of teaching. how can this, thankful you. here canvas example. edit: here complete code:

<canvas id="c" style="border:1px solid black;" width="500px" height="300px" ></canvas> <button onclick="myfunction()" id="btn2">click me</button> <script type="text/javascript" src="fabric.min.js"></script> <script type="text/javascript"> var canvas = new fabric.canvas('c'); $(function () {          //canvas.stateful = true;     var wel = new fabric.text('welcome fabricjs', {         fontfamily: 'delicious_500',         backgroundcolor: 'red',         left: 80,          top: 100      });     canvas.add(wel); }); canvas.renderall(); function myfunction() {     console.log(json.stringify(canvas));     var str_json = json.stringify(canvas);     // send json php     $.ajax({         type: 'post',         url: 'hallo_json.php',         datatype: 'json',         contenttype: 'application/json; charset=utf-8',         data: { hallo_str: json.stringify(str_json) },      });          alert(str_json);  }  </script> 

here php code:

<?php header('content-type: text/html'); print_r(json_decode($_post['str_json'])); 

now can generate json, error 200 arises. don't error.

you can use canvas method todataurl. returns string data type , format followed base64 encoded image data. data can send server decode , save image.


Popular posts from this blog