barryvdh / laravel-elfinder

elFinder bundle for Laravel
738 stars 171 forks source link

Trying to use Laravel Flysystem disks #138

Open dbr0 opened 8 years ago

dbr0 commented 8 years ago

I'm rather new to this so please bare with me.

While developing my app localy I was saving all the files locally to folder defined in config/elfinder.php in dir.

But I will need to use the Amazon's S3 so I'm moving to using Flydisk. I set up dir value to '' (empty) and added to disks following:

 'local' => [
        //'URL' => url('storage/app/dokuments'), //note to myself, cant use url() here, composer won't update, migrations won't run
        'URL' => ('storage/app/dokuments')
        'alias' => 'Local storage',
        'path' => 'string-to-be-replaced',
    ]

I found the path option here: https://github.com/Studio-42/elFinder/wiki/Connector-configuration-options-2.1#root-options

Ok, so my root folder now is storage/app/dokuments.

Next, in vendor files in ElfinderController.php I added the line

        $disks = (array) $this->app['config']->get('elfinder.disks', []);
        /*rooting user to his folder using Storage::disk*/
        $disks['local']['path'] = \Auth::user()->slug.'-'.\Auth::user()->id;

The second two lines are new. This is done so the each user will be rooted in his own folder. I am aware that I shouldn't mess with vendor files and that I will have to fix this after each composer update so please point me to another way to solve this if possible.

Now everything works, user is rooted where he should be, but whenever I try to upload a file to this folder I get undefined index: url and file is shown only when I reopen the elfinder.

This could be due to the fact that in ElfinderControler.php '-.- I have alse commented out following:

        foreach ($dirs as $dir) {
            $roots[] = [
                //'driver' => 'LocalFileSystem', // driver for accessing file system (REQUIRED)
                //'path' => public_path($dir), // path to files (REQUIRED)
                //'URL' => url($dir), // URL to files (REQUIRED)
                'accessControl' => $this->app->config->get('elfinder.access') // filter callback (OPTIONAL)
            ];
        }

I would like to solve this before I go to figuring out S3 because I feel I'll end up with the same problem and this way at least I know that the problem is me hacking the Elfinder and not me not understanding Flysystem or S3.

Thanks!

SHORT UPDATE: I can delete files normally and if in `config/elfinder.php I replace

        'path' => 'string-to-be-replaced',

with

        'path' => 'string-to-be-replaced',
        'URL' => 'string-to-be-replaced',

and in 'ElfinderController.php' i replace

        $disks['local']['URL'] = \Auth::user()->slug.'-'.\Auth::user()->id;

with

        $disks['local']['path'] = \Auth::user()->slug.'-'.\Auth::user()->id;
        $disks['local']['URL'] = \Auth::user()->slug.'-'.\Auth::user()->id;

I get the same undefined index: url error. I also tried replacing second line here with:

        $disks['local']['URL'] = url(\Auth::user()->slug.'-'.\Auth::user()->id);

or

        $disks['local']['URL'] = 'https://s3.eu-central-1.amazonaws.com/mybucket/' . \Auth::user()->slug.'-'.\Auth::user()->id

Still the same error.

dbr0 commented 8 years ago

I believe this error also makes multiple uploads impossible. I just noticed this problem so can't be 100% sure.

At this moment I'm looking at any kind of workaround to make this work, or any kind of suggestion.

Also I can't find the code that generate this error.