Reputation: 65
I'm having difficulties passing a var to Ckfinder for it to open the folder matching the currently edited page.
The wanted folder has the same name as my database field "gallery" that I can pass in the url this way :
$url_edit = 'modifier-' . $_GET['page'] . '-' . $data["id"] . '-' . $data['gallery'] . '';
// RewriteRule ^modifier-(.*)-([0-9]+)-(.*)$ admin.php?modif=$1&id=$2&dir=$3 [L]
I think this part of Ckfinder's config.php could be the best spot to pass my var $_GET['dir']
and point to the specific folder (default : 'photos') :
if(isset($_GET['dir'])) {
die(var_dump('DEBUG')); // DEBUG
$galleryDir = '/' . $_GET['dir'];
}
$config['resourceTypes'][] = array(
'name' => 'Photos',
'directory' => 'photos' . $galleryDir . '' ,
'maxSize' => 0,
'allowedExtensions' => 'bmp,gif,jpeg,jpg,png',
'deniedExtensions' => '',
'backend' => 'default'
);
I'm opening Ckfinder as a modal using this code from the official documentation (I didn't alter this as I'm not confortable with Javascript) :
var button1 = document.getElementById( 'ckfinder-galerie' );
button1.onclick = function() {
selectFileWithCKFinder( 'ckfinder-input-1' );
};
function selectFileWithCKFinder( elementId ) {
CKFinder.modal( {
chooseFiles: true,
width: 800,
height: 600,
onInit: function( finder ) {
finder.on( 'files:choose', function( evt ) {
var file = evt.data.files.first();
var output = document.getElementById( elementId );
output.value = file.getUrl();
} );
finder.on( 'file:choose:resizedImage', function( evt ) {
var output = document.getElementById( elementId );
output.value = evt.data.resizedUrl;
} );
}
} );
}
PROBLEM : $_GET['dir']
doesn't seem to be passed through the modal, so it currently doesn't create the needed $galleryDir
var (nor the die()
function used for debug). Am I doing something wrong here ? I'm also open to other methods if this one isn't as good as I believe.
Thanks for the future help !
Upvotes: 0
Views: 85
Reputation: 65
Thanks to the lead given by CBroe I figured out a way to pass the variable. Not 100% efficient but satisfying enough for my needs :
Passing the var in a session before loading Ckfinder :
if(isset($_GET['dir'])) {
$_SESSION['dir'] = $_GET['dir'];
}
Then retrieving it in Ckfinder's config.php to dynamically create the new directory variable :
if(isset($_SESSION['dir'])) {
$galleryDir = '/' . $_SESSION['dir'];
}
$config['resourceTypes'][] = array(
'name' => 'Photos',
'directory' => 'photos' . $galleryDir . '' ,
'maxSize' => 0,
'allowedExtensions' => 'bmp,gif,jpeg,jpg,png',
'deniedExtensions' => '',
'backend' => 'default'
);
It works perfectly : the modal focuses on the wanted folder matching the edited page. Passing a specific directory url disallow the ability to browse the folders though as "directory" var considers itself as the root folder.
Upvotes: 0