0

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!

Ray
  • 781
  • 2
  • 17
  • 42
  • Don't save files in a database. http://stackoverflow.com/a/38829952/267540 specially not base64 encoded ones. In fact try not to base64 encode them at all – e4c5 Dec 14 '16 at 02:12
  • hmm.. I want the user to be able to upload image and summernote provides this feature, however, if you look at the code behind you will see that each image has been converted to base64 automatically – Ray Dec 14 '16 at 02:13
  • and that's still wrong. – e4c5 Dec 14 '16 at 02:25
  • I need such an editor like that to let the admin customize a specific area of his page. How would you create that? – Ray Dec 14 '16 at 02:29
  • Decode the Base64 data and write it to a file. Store the path to the file in the database. – Jordan Running Dec 14 '16 at 02:36

1 Answers1

0

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.

Ray
  • 781
  • 2
  • 17
  • 42