php - Laravel 5 覆盖summernote 图片上传

标签 php jquery laravel-5 image-upload summernote

我想用 laravel 5 方法 ajax 覆盖 Summernote 中的图像上传,但我无法让它工作。

这是我的 php 方法

public function ajaxImage()
{
    $file = Input::file('image');
    $destinationPath = public_path();
    $filename = $file->getClientOriginalName();
    if(Input::file('image')->move($destinationPath, $filename)) {
        echo $destinationPath.$filename;
    }
}

这是我的 jquery 代码:

$(document).ready(function(){
            $('#description').summernote({
                height: 300,

                onImageUpload: function(files, editor, welEditable) {
                    sendFile(files[0], editor, welEditable);
                }
            });
            function sendFile(file, editor, welEditable) {
                var  data = new FormData();
                data.append("file", file);
                var url = '/articles/ajaximage';
                $.ajax({
                    data: data,
                    type: "POST",
                    url: url,
                    cache: false,
                    contentType: false,
                    processData: false,
                    success: function(url) {
                        alert('Success');
                        editor.insertImage(welEditable, url);
                    }
                });
            }
        });

我在控制台中收到错误:

发布http://marcus.dev/articles/ajaximage 500(内部服务器错误)

最佳答案

对于 Summernote 0.6.9 版本,我们无法再在回调函数中使用编辑器。

而不是

editor.insertImage(welEditable, url);

我用过

$('#summernote').summernote('editor.insertImage', url);

我不知道是否有更干净的版本,但它似乎可以工作。

关于php - Laravel 5 覆盖summernote 图片上传,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29866300/

相关文章:

php - 为什么这个 ajax 脚本不能在 wamp 本地主机上工作

php - 从 URI 和 Web Root 中提取公共(public)路径

javascript - 覆盖 Bootstrap 有错误类

php - laravel 中的多数组验证

mysql - Laravel 5.7 中修改后的用户注册停止工作(字段 'last_name' 没有默认值,但数据完整)

php - 如何在php中使用数据库中的数据设置“阅读更多”按钮

php - 如何从 PHP 数组中获取每个键值对

JMeter 中的 JQuery 表达式

jquery - 使用 jQuery 动态添加自定义 HTML 表单文件输入

javascript - 数组到 JavaScript 字符串