You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

不搭配CKEditor使用CKFinder上传多图无法获取全部URL如何修改代码

解决方案

你已经定位到问题根源是仅调用first()方法获取了首个选中文件。evt.data.files是CKFinder提供的文件集合对象,支持forEach方法遍历所有选中文件,你可以通过遍历操作把所有文件URL存入数组,修改后的代码如下:

window.CKFinder = {
        _popupOptions: {
            'popup-1-config': { // 第一个弹窗的配置ID
                chooseFiles: true,
                onInit: function( finder ) {
                    finder.on( 'files:choose', function( evt ) {
                        var selectedFiles = evt.data.files;
                        var selectedUrls = []; // 存储所有选中文件URL的数组
                        var output = document.getElementById( 'output' );
                        var outputHtml = '弹窗1选中的文件:<br>';

                        // 遍历所有选中文件
                        selectedFiles.forEach(function(file) {
                            // 将文件URL存入数组
                            selectedUrls.push(file.getUrl());
                            // 拼接页面展示内容,可根据需求调整
                            outputHtml += `文件名:${file.get('name')}<br>URL:<img src="${file.getUrl()}" style="max-width: 200px; margin: 8px 0;"><br>`;
                        });

                        output.innerHTML = outputHtml;
                        // 后续可直接使用selectedUrls数组完成表单赋值等业务逻辑
                        console.log('所有选中文件URL数组:', selectedUrls);
                    } );
                }
            },
            
        }
    };

    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() {
        // 注意配置ID通过configId参数传递
        window.open( 'http://foxhills.localhost/admin/ckfinder/ckfinder.html?popup=1&amp;configId=popup-1-config', 'CKFinderPopup1', popupWindowOptions );
    };

如果不需要在页面展示选中文件,只保留数组存储逻辑即可。


内容的提问来源于stack exchange,提问作者user2468312

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.09.27 13:36:04