How can I save a large base64 image that is generated through summernote in my database?

1.4k views Asked by At

I am having a problem trying to save an image that is generated by summernote editor in my database. I am guessing that it is a character size issue. The column that I am trying to save the code of the summernote has 'Long Text' datatype.

My code is like the following, the request established in JS, it goes to the model, and then the model calls a function that is inside the controller

Javascript request

function setupSummerNote(){
    $('#summernote').summernote({
        height: 600,                 // set editor height
        minHeight: null,             // set minimum height of editor
        maxHeight: null,             // set maximum height of editor
        focus: true                  // set focus to editable area after initializing summernote
    });
    $.get("./get-section").done(function(data) {
        if(data)
        {
            $('#summernote').summernote('code', data);
        }
    });

    $('.note-editable').blur(function(){
        var code = $('#summernote').summernote('code');
        $.post("./update-setion", {code: code}).done(function(data) {

        });
    });
}

The Model

public function updateContent()
{
    $code = $_POST['code'];
    $modelAdmin = new Model_Admin();
    $modelAdmin->updateSection($code);
}

The Controller

public function updateSection($code)
{
    $this->connect();
    $query = $this->db->prepare("UPDATE `Content` SET content = ? WHERE id = ?");
    $result = $query->execute(array($code, '1')); // $code: html content of the summernote 
}

how do you think I can solve this problem?

Thanks!

1

There are 1 answers

0
Ray On

I created a solution for my problem. It is not the best but it works. All I needed to do is cut the string that I am getting into multiple strings (5000 characters each) and then store it in the database. Then concatenate all the strings together in case I want to retrieve the content.