Elfinder AJAX - Data is not JSON

2.9k Views Asked by At

I am currently getting the folling error when trying to upload an image in Elfinder:

Invalid backend response. Data is not JSON.

I am 95% sure is is a ajax issue as when I take the code out of the switch it works just fine. Even in the switch I am able to view all files and directories but uploads are still an issue

Here is my 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);
}

And here is my 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');
0

There are 0 best solutions below