0

I've been stuck for so many days on this. I'm seeing a lot of the same problem like this, but some of the codes from them won't work on me. To be precise, I'm not using php 5 nor 7. But this is what I've got so far.

(Assuming there are drawings in this canvas) my html:

    <canvas id="displaycanvas" height="400px" width="700px" style="position:absolute; background-image:url('images/canvas_pattern.jpg');background-attachment:fixed;"> </canvas>

    <canvas id="display_text" height="400px" width="700px" style="position:absolute;" > </canvas>

<input type="button" name="btn" id="submitBtn" value="display" class="btn btn-primary" />

And I successfully converted my canvas to image and displays it!

$(function () {
    $("#submitBtn").bind("click", function () {
        var display01 = $('#displaycanvas')[0].toDataURL();
        $("#show_canvas").attr("src", display01);
        $("#show_canvas").show();
    });
});

display part of the image: (works fine)

<img id="show_canvas" name="show_canvas" height="400px" width="700px"/>

now after displaying, I have a button "save" which means to store the image or canvas in my database and it executes at the "submit.php".

but I'm stuck on how am I going to store it in my database... right now I only have a primary key on my "Image_table", not sure what are the right attributes to add.

Thank you in advance!!

Khyana
  • 195
  • 1
  • 14
  • I wouldn't store the image in your database, i would store reference to it. so you would pass your image data to your server, save it as a file then store the path to that file in your database. – cmorrissey Feb 08 '17 at 20:26
  • @cmorrissey i've heard blob isn't really advantage to use, yes.. I wanted a path thing to store in my local folders that I've prepared. But I have no idea how to do it. – Khyana Feb 08 '17 at 20:28
  • You should start with some php code, I see nothing you have tried anything database related or path related. – Nytrix Feb 08 '17 at 20:29
  • @Nytrix I really don't know where to start on storing images,.. but uploading image isn't what I've wanted. just wanted to store the canvas (converted) to the database using path – Khyana Feb 08 '17 at 20:34
  • @Nytrix well I tried something like this. attribute - canvasimage VARCHAR(255) (database) submit.php = `$_canvasimage = $_POST['show_canvas']; query1 = "Insert into image_table values ('$canvasimage')";` – Khyana Feb 08 '17 at 20:38
  • 1
    your image when converted to base64 will be MUCH larger than 255 bytes. If you really don't want to save the image normally and you want to put the image data in the database, you'll need a bigger datatype. Just so you know there is absolutely no point in putting the image data into the database over just saving the image as a file. – CodeCabin Feb 08 '17 at 20:55
  • Yes export your canvas as blob, store as file, save the path of where you stored the file http://stackoverflow.com/questions/34711715/phpjs-how-to-do-fileuploads-in-html-form-as-content-type-multipart-via-js/34713226#34713226 – Kaiido Feb 08 '17 at 23:28

0 Answers0