sunhater / kcfinder

KCFinder web file manager
http://kcfinder.sunhater.com
402 stars 209 forks source link

Dynamically changing the uploadDir via a session variable creates unwanted subfolders #144

Open chocolata opened 8 years ago

chocolata commented 8 years ago

Hi

I'm using KCfinder 3.12 for a while now and I am loving it. Everything works fine, but I now want to take it to the next level.

My client has an online shop. Each item has its own folder within userfiles. Folder structure is as follows:

/userfiles/files
/userfiles/images
/userfiles/items

Within /userfiles/items there's a subfolder with for each item. I'm using CKeditor as well. It's configured to put its images in /userfiles/images and its files in /userfiles/files. This way, my client does not have access to the global items folder.

Now upon creating an item, a folder is created within /userfiles/items to store the images of that item. Since I want my client to only have to deal with the images of the item he's modifying, I've overridden the uploadDir as follows:

$_SESSION['KCFINDER']['uploadDir'] = '/var/www/vhosts/website.org/httpdocs/userfiles/items/'.$id_of_item;

This works well, but for some reason, it makes KCFinder create a folder called items inside the wanted folder... So the result of the above statement is:

/userfiles/items/5555/items/image.jpg instead of /userfiles/items/5555/image.jpg

I've tried removing the types in config.php, tried putting an empty string as suggested here. Sometimes they do put KCFinder in the right root directory, but then I get the error "unkown error" and the thumbnails are missing.

Some extra info, I'm calling KCFinder like so:

    $(".add_images").click( function(e) {
        e.preventDefault();
        window.KCFinder = {
            callBackMultiple: function(files) {
                window.KCFinder = null;
                for (var i = 0; i < files.length; i++) {
// yadayada, you know this part
                    });
                }
            }
        };
        window.open(site_root + '/js/vendor/kcfinder/browse.php?type=items&langCode=nl',
            'kcfinder_image', 'status=0, toolbar=0, location=0, menubar=0, ' +
                'directories=0, resizable=1, scrollbars=0, width=800, height=600');
        $('#edit_form').change();
    });

My config PHP has the types configured like this:

'types' => array(
        // Custom type for my items
        'items'  =>  "*img",
        // (F)CKEditor types
        'files'   =>  "",
        'flash'   =>  "disabled",
        'images'  =>  "*img",
        // TinyMCE types
        'file'    =>  "",
        'media'   =>  "disabled",
        'image'   =>  "*img"
    ),

Could anyone please provide some insight? Thanks a lot in advance.