Summernote图片上传错误 [英] Summernote image upload error

查看:484
本文介绍了Summernote图片上传错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用codeigniter,twitter bootstrap和summernote作为我的WYSIWYG编辑器。我面临着图片上传的一些问题。每当使用Summernote上传图像时,它都会将图像序列化为base64字符串。那个base64字符串很长,以至于它不适合phpmyadmin中的文本数据类型。我想要做的是,使用PHP上传功能上传图像并将其url存储在数据库而不是base64字符串中。我该怎么做?

I'm using codeigniter, twitter bootstrap and summernote as my WYSIWYG editor. Im facing some problem with the image upload. Whenever uploading an image using Summernote, it serializes the image in a base64 string. That base64 string is so long that it doesnt fit in the text data-type in phpmyadmin. What i want to do is, upload the image using PHP upload function and store its url in the database instead of the base64 string. How would i do that?

参考这个发布,这是代码,

$(function() {
  $('.summernote').summernote({
    height: 100,
    onImageUpload: function(files, editor, welEditable) {
            sendFile(files[0], editor, welEditable);
        }
  });
  function sendFile(file, editor, welEditable) {
        data = new FormData();
        data.append("files", file);
        upload_url = "<?php echo base_url(); ?>" + "dashboard/uploader/";
        $.ajax({
            data: data,
            type: "POST",
            url: upload_url,
            cache: false,
            contentType: false,
            processData: false,
            success: function(url) {
                editor.insertImage(welEditable, url);
            }
        });
    }
});

仪表板类中的上传器方法是我的php上传代码所在的位置。这是PHP代码,

the uploader method in the dashboard class is where my php upload code resides. Here's the PHP code,

public function uploader()
{
    $this->load->helper('file');
    if ($_FILES['files']['name']) {
        if (!$_FILES['files']['error']) {
            $name = md5(rand(100, 200));
            $ext = explode('.', $_FILES['files']['name']);
            $filename = $name . '.' . $ext[1];
            $destination = base_url().'uploads/' . $filename; 
            $location = $_FILES["files"]["tmp_name"];
            move_uploaded_file($location, $destination);
            echo base_url() . $filename; 
        }
        else
        {
          echo  $message = 'Ooops!  Your upload triggered the following error:  '.$_FILES['files']['error'];
        }
    }
}

每当我上传图片时,它没有在wysiwyg编辑器中显示它。我哪里错了?

Whenever i upload the image, it doesnt show it in the wysiwyg editor. Where am i going wrong?

现在看起来像这样:

$(function() {
  $('.summernote').summernote({
    height: 100,
    onImageUpload: function(files) {
            sendFile(files[0]);
        }
  });
  function sendFile(file) {
        data = new FormData();
        data.append("files", file);
        upload_url = "<?php echo base_url(); ?>" + "dashboard/uploader/";
        $.ajax({
            data: data,
            type: "POST",
            url: upload_url,
            cache: false,
            contentType: false,
            processData: false,
            success: function(url) {
                 $(this).summernote("insertImage", url);
            }
        });
    }
});


推荐答案

您使用的是哪个版本的summernote?最新的(0.6.16)summernote调用自定义 OnImageUpload 函数只有一个参数 - 文件,没有编辑 welEditable

Which version of summernote are you using? Latest (0.6.16) summernote calls custom OnImageUpload function with only one argument - files, without editor and welEditable.

参见:
https://github.com/summernote/summernote/blob/v0 .6.16 / src / js / EventHandler.js#L117

请参考 javascript代码 django-summernote

在0.6.5之后,Summernote改变了处理图像的行为。请参阅更改

Summernote changed its behavior on handling images after 0.6.5. See changes.

这篇关于Summernote图片上传错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆