1

尝试在 Elfinder 中上传图像时,我目前遇到以下错误:

后端响应无效。数据不是 JSON。

我 95% 确定这是一个 ajax 问题,因为当我将代码从开关中取出时,它工作得很好。即使在交换机中,我也可以查看所有文件和目录,但上传仍然是个问题

这是我的PHP:

if (isset($_SERVER['HTTP_X_REQUESTED_WITH']) && ($_SERVER['HTTP_X_REQUESTED_WITH'] == 'XMLHttpRequest'))
{
    $admin      = new systemAdmin;

    $response   = array('ok' => 0);
    $type       = (isset($_GET['type'])) ? $_GET['type'] : '';

    switch ($type)
    {
        case 'connector':

            if(in_array('filemanager',$admin->user_auth['authority']))
            {
                include_once($admin->get_setting(5) . '/classes/core/class.elFinderConnector.php');
                include_once($admin->get_setting(5) . '/classes/core/class.elFinder.php');
                include_once($admin->get_setting(5) . '/classes/core/class.elFinderVolumeDriver.php');
                include_once($admin->get_setting(5) . '/classes/core/class.elFinderVolumeLocalFileSystem.php');

                $opts = array(
                    'locale' => 'en_US.UTF-8',
                    'roots' => array(
                        array(
                            'driver'     => 'LocalFileSystem',
                            'path'          => $admin->get_setting(5) . '/media/',
                            'startPath'     => $admin->get_setting(5) . '/media/',
                            'URL'           => $admin->get_setting(2) . '/media/',
                            'treeDeep'      => 3,
                            'alias'         => 'Filemanager',
                            'mimeDetect'    => 'internal',
                            'tmbPath'       => '_thumbs',
                            'utf8fix'       => true,
                            'tmbCrop'       => true,
                            'tmbBgColor'    => 'transparent',
                            'accessControl' => 'access',
                            'acceptedName'  => '/^[^\.].*$/',
                            'attributes' => array(
                                array(
                                    'pattern' => '/\.js$/',
                                    'read' => false, 'write' => false, 'hidden' => true, 'locked' => true
                                ),
                                array(
                                    'pattern' => '/\.htaccess$/',
                                    'read' => false, 'write' => false, 'hidden' => true, 'locked' => true
                                ),
                                array(
                                    'pattern' => '/_thumbs/',
                                    'read' => false, 'write' => false, 'hidden' => true, 'locked' => true
                                ),
                                array(
                                    'pattern' => '/featured/',
                                    'read' => false, 'write' => false, 'hidden' => true, 'locked' => true
                                )
                            )
                        ),
                    )
                );

                header('Access-Control-Allow-Origin: *');
                $connector = new elFinderConnector(new elFinder($opts), true);
                $connector->run();
            }

        break;

    }

    ob_clean();
    header('Cache-Control: no-cache, must-revalidate');
    header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
    header('Content-type: application/json');
    echo json_encode($response);
}

这是我的 JS:

        var funcNum = getUrlParam('CKEditorFuncNum');
        var elf = $('#fileManager').elfinder({
                commandsOptions : {
                getfile : {
                    onlyURL  : true,
                    multiple : false,
                    folders  : false,
                    oncomplete : ''
                }
            },
            height: '488', 
            url : '/ajax.html?type=connector',
            getFileCallback : function(getfile) {
                window.opener.CKEDITOR.tools.callFunction(funcNum, getfile);
                window.close();
            },
            resizable: false
        }).elfinder('instance');
4

0 回答 0