简体   繁体   English

正确的elFinder和CKeditor集成以直接上传文件

[英]right elFinder and CKeditor integration to upload files directly

I uses elFinder laravel package file Manager with ckeditor. 我使用ckeditor的elFinder laravel软件包文件管理器。 I follow all Instructions step and all things work except one. 我遵循所有说明步骤,除一个步骤外,所有其他操作均正常。

When I click on image button in ckEditor to select (or upload) an Image , on the upload tab after select an image from my computer and click Send it to the Server button NotFoundHttpException in RouteCollection.php line 161 shown and upload fails. 当我在ckEditor中单击图像按钮以选择(或上传)图像时,在从我的计算机中选择图像后,在上传选项卡上单击 NotFoundHttpException in RouteCollection.php line 161 其发送到服务器按钮NotFoundHttpException in RouteCollection.php line 161然后上传失败。

this is ckEditor initialization code : 这是ckEditor初始化代码:

<textarea name="content_fa" id="fa_post_content" class="form-control"
          rows="10"></textarea>
<script>
    var fa_post_content = CKEDITOR.replace('fa_post_content', {
        toolbar: 'admin_mode',
        filebrowserBrowseUrl : '{{route('elfinder.ckeditor')}}',
        filebrowserUploadUrl : '/elfinder/connector.php?cmd=upload'
    });
</script>

According to This Issue , I add filebrowserUploadUrl option as you see above. 根据此问题 ,如上所述,我添加了filebrowserUploadUrl选项。 but this not work too. 但这也不行。

How can I solve this ? 我该如何解决?

This code (+ DnD upload) using demo site is here . 使用演示站点的此代码(+ DnD上传) 在此处

CKEDITOR.on('dialogDefinition', function (event) {
    var editor = event.editor,
        dialogDefinition = event.data.definition,
        tabCount = dialogDefinition.contents.length,
        uploadButton, submitButton, inputId,
        elfUrl = editor.config.filebrowserUploadUrl,
        // elFinder configs
        elfDirHashMap = { // Dialog name / elFinder holder hash Map
            image : '',
            flash : '',
            files : '',
            link  : '',
            fb    : 'l1_Lw' // fallback target
        },
        customData = {}; // any custom data to post

    for (var i = 0; i < tabCount; i++) {
        uploadButton = dialogDefinition.contents[i].get('upload');
        submitButton = dialogDefinition.contents[i].get('uploadButton');

        if (uploadButton !== null && submitButton !== null) {
            uploadButton.hidden = false;
            submitButton.hidden = false;
            uploadButton.onChange = function() {
                inputId = this.domId;
            }
            submitButton.onClick = function(e) {
                dialogName = CKEDITOR.dialog.getCurrent()._.name;
                var target = elfDirHashMap[dialogName]? elfDirHashMap[dialogName] : elfDirHashMap['fb'],
                    name   = $('#'+inputId),
                    input  = name.find('iframe').contents().find('form').find('input:file'),
                    error  = function(err) {
                        alert(err.replace('<br>', '\n'));
                    };

                if (input.val()) {
                    var fd = new FormData();
                    fd.append('cmd', 'upload');
                    fd.append('overwrite', 0); // disable upload overwrite to make to increment file name
                    fd.append('target', target);
                    $.each(customData, function(key, val) {
                        fd.append(key, val);
                    });
                    fd.append('upload[]', input[0].files[0]);
                    $.ajax({
                        url: elfUrl,
                        type: 'POST',
                        data: fd,
                        processData: false,
                        contentType: false,
                        dataType: 'json'
                    })
                    .done(function( data ) {
                        if (data.added && data.added[0]) {
                            var url = data.added[0].url;
                            var dialog = CKEDITOR.dialog.getCurrent();
                            if (dialogName == 'image') {
                                var urlObj = 'txtUrl'
                            } else if (dialogName == 'flash') {
                                var urlObj = 'src'
                            } else if (dialogName == 'files' || dialogName == 'link') {
                                var urlObj = 'url'
                            } else {
                                return;
                            }
                            dialog.selectPage('info');
                            dialog.setValueOf(dialog._.currentTabId, urlObj, url);
                        } else {
                            error(data.error || data.warning || 'errUploadFile');
                        }
                    })
                    .fail(function() {
                        error('errUploadFile');
                    })
                    .always(function() {
                        input.val('');
                    });
                }
                return false;
            }
        }
    } 
});

For anyone running into this issue now, the thing that resolved it for me was setting filebrowserBrowseUrl. 对于现在遇到此问题的任何人,为我解决的问题是设置filebrowserBrowseUrl。 The mistake I was making was setting filebrowserUploadUrl instead of the filebrowserBrowseUrl. 我犯的错误是设置filebrowserUploadUrl而不是filebrowserBrowseUrl。 Elfinder handles the upload inside itself, so you should not have to use the 'send to the server' button at all, just the browse server button. Elfinder本身处理上传文件,因此您根本不必使用“发送到服务器”按钮,而只需使用浏览服务器按钮。

So the ckeditor code looked like such 所以ckeditor代码看起来像这样

CKEDITOR.replace('your-id-here', {

    filebrowserBrowseUrl: '/elfinder/ckeditor',

    }
);

noting to replace your-id-here with your own id. 注意将您的ID替换为您自己的ID。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM