i'm using fmelfinder in association tinymce managing assets (images, pdf ...) of users (managed fosuserbundle)
i've seen tool can handle multiple root folder, in case, isn't quite usable : have root folder each user.
in configuration file app/config/config.yml, there root path(s) defined :
fm_elfinder: instances: default: locale: %locale% ... connector: roots: uploads: driver: localfilesystem path: uploads/data
i thining "simply" changing path :
path: uploads/data/{the_username}
where username username of logged user
in controller can
$user = $this->get('security.token_storage')->gettoken()->getuser(); $username = $user->getusername();
but i don't know if it's possible (and if so, how) access username of logged user config file
thank if have suggestion
=================[edit] ==========================================
i've use override of configuration. think followed steps, haven't managed make work :
1 - create class
use fm\elfinderbundle\model\elfinderconfigurationproviderinterface; use symfony\component\dependencyinjection\containerinterface; class elfinderconfigurator implements elfinderconfigurationproviderinterface { protected $container; protected $options; /** * @param containerinterface $container */ public function __construct($options, containerinterface $container) { $this->container = $container; $this->storage = $container->get('security.token_storage'); $this->options = $options; } /** * @param $instance * * @return array */ public function getconfiguration($instance) { //retrieve basepath $basepath_abs = $this->container->get('kernel')->getrootdir()."/../web/uploads"; $basepath = "uploads/data"; //define path user $userid = $this->storage->gettoken()->getuser()->getid(); $root = $basepath.'/'.$userid; $this->options['instances']['default']['connector']['roots']['uploads']['path'] = $root.'/root'; $this->options['instances']['default']['connector']['roots']['uploads']['upload_max_size'] = '2m'; $option = [ 'corssupport' => false, 'roots' => $this->options['instances']['default']['connector']['roots'], ]; $root_abs = $basepath_abs.'/data/'.$userid; //creates dir if not available if (!is_dir($root_abs)) { mkdir($root_abs.'/root', 0775, true); } return $option; } }
2 - set service :
myvendor.mybundle.elfinder_configurator: class: myvendor\mybundle\services\elfinderconfigurator arguments: ["%fm_elfinder%", "@service_container"]
3 - call service in app/config/config.yml
fm_elfinder: configuration_provider: myvendor.mybundle.elfinder_configurator ...
it works partially : when open elfinde, directory correctly created if don't exists. there must a path problem, , i'm not sure it's well overriden because : - thumbs not displayed in elfinder - when add image editor, don't have correct path of image, have :
//app_dev.php/efconnect?cmd=file&target=l1_q2fwdhvyzsbkj8opy3jhbibkzsaymde2ltaxlti0ide0ojm2oji0lnbuzw
instead of actual path of image (if don't use override, tool works , gives me path)
../../../../uploads/data/1/root/img1.png
and no image displayed.
also, if in js console
efconnect?cmd=open&target=&init=1&tree=1&_=1469377765664
i see uplmaxsize 200m,
in case, there no js error in console
i think looking custom config provider:
https://github.com/helios-ag/fmelfinderbundle/blob/master/resources/doc/advanced-configuration.md#custom-configuration-provider
you inject token storage service , fetch user in controller:
services: my_elfinder_configurator: class: acme\demobundle\elfinder\userawareconfigurator arguments: ["@token_storage", "%any_container_params%"]
Comments
Post a Comment