简体   繁体   English

没有CKEditor的CKfinder多张图片上传

[英]CKfinder multiple image upload without CKEditor

I am using the ckfinder modal without CKEditor to upload multiple files to the form section.我正在使用没有 CKEditor 的 ckfinder 模式将多个文件上传到表单部分。

I used the code provided in the documentation section,我使用了文档部分提供的代码,

CKfinder modal opens as expected, selected multiple file but i couldn't able to get all the images url. CKfinder 模式按预期打开,选择了多个文件,但我无法获取所有图像 url。 The response i got only the first image.我只得到了第一张图片的回应。

window.CKFinder = {
        _popupOptions: {
            'popup-1-config': { // Config ID for first popup
                chooseFiles: true,
                onInit: function( finder ) {
                    finder.on( 'files:choose', function( evt ) {
                        var file = evt.data.files.first();
                        var output = document.getElementById( 'output' );
                        output.innerHTML = 'Selected in popup 1: ' + file.get( 'name' ) + '<br>URL: <img src=" ' + file.getUrl() + '">';
                    } );
                }
            },
            
        }
    };

    var popupWindowOptions = [
        'location=no',
        'menubar=no',
        'toolbar=no',
        'dependent=yes',
        'minimizable=no',
        'modal=yes',
        'alwaysRaised=yes',
        'resizable=yes',
        'scrollbars=yes',
        'width=800',
        'height=600'
    ].join( ',' );

    document.getElementById( 'popup-1-button' ).onclick = function() {
        // Note that config ID is passed in configId parameter
        window.open( 'http://foxhills.localhost/admin/ckfinder/ckfinder.html?popup=1&configId=popup-1-config', 'CKFinderPopup1', popupWindowOptions );
    };

In the above code var file = evt.data.files.first();在上面的代码中var file = evt.data.files.first(); is the reason why i am getting the first image.是我得到第一张图片的原因。 How i can change the code to get the all the urls as array.我如何更改代码以获取所有 url 作为数组。

For your event, try testing with this对于您的活动,请尝试使用此测试

finder.on( 'files:choose', function( evt ) {
    var files = evt.data.files;

    var chosenFiles = '';

    files.forEach( function( file, i ) {
        chosenFiles += ( i + 1 ) + '. ' + file.get( 'name' ) + '\n';
    } );

    alert( chosenFiles );
} );

Source: https://ckeditor.com/docs/ckfinder/ckfinder3/#!/api/CKFinder.Application-event-files_choose来源: https : //ckeditor.com/docs/ckfinder/ckfinder3/#!/api/CKFinder.Application-event-files_choose

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

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