Issue displaying images with Laravel file manager. Routes question

Viewed 1282

I'm messed with the paths to get UniSharp / laravel-filemanager working on the server. In local mode it works perfectly but now I'm making the change of routes for production in online mode and I am not clear at all.

The problem is that it loads the images but they are not displayed either on the page or in the filemanager itself. In filemanager, I can see a red square with a cross (as error). Let's see if anyone knows how to write the correct routes. I have tried many things but I'm messed.

The server files scaffolding:

  • server_files
  • my_laravel_app
  • public_html
    • another_files

The config filesystem.php file in Laravel:

'disks' => [
        'local' => [
            'driver' => 'local',
            'root' => storage_path('app'),
        ],
        'public' => [
            'driver' => 'local',
            'root' => storage_path('public_html'),
            'url' => env('APP_URL').'/storage',
            'visibility' => 'public',
        ],
        's3' => [
            'driver' => 's3',
            'key' => env('AWS_ACCESS_KEY_ID'),
            'secret' => env('AWS_SECRET_ACCESS_KEY'),
            'region' => env('AWS_DEFAULT_REGION'),
            'bucket' => env('AWS_BUCKET'),
            'url' => env('AWS_URL'),
            'endpoint' => env('AWS_ENDPOINT'),
        ],
    ],
  'links' => [
    public_path('storage') => storage_path('app/public'),
],

I have, default uploading path in filemanager's lfm.php:

'disk'  => 'public',

In case it helps something, this is my index.php ubicated at public_html:

if (file_exists(__DIR__.'/../my_app_laravel/storage/framework/maintenance.php')) {
    require __DIR__.'/../my_app_laravel/storage/framework/maintenance.php';
}
require __DIR__.'/../my_app_laravel/vendor/autoload.php';
$app = require_once __DIR__.'/../my_app_laravel/bootstrap/app.php';

And this is ServiceProviders.php

 public function register()
    {
        $this->app->bind('path.public', function() {
            return base_path().'/public_html';
        });
    }

How should be the correct path in filesystem to allow filemanager can access to images and display them?

Note: the public_html folder has the symbolic link as you can see at filesystem.php.

1 Answers

I have checking routes and I solved temporary:

I changed:

'public' => [
    'driver' => 'local',
    /* this */  'root' => storage_path('app/public'),
    /* this */  'url' => env('APP_URL').'/storage/app/public',
    'visibility' => 'public',
],

And now I can upload and see the images in file manager and inside the web app. But now the problem is that users can visit the image url and see the private route of the folder:

http//mi_lar_app/storage/app/public/photos/31/art_1/fig_1.0.png

Some help????

If you have similar problems, the procedure I do in this case was to create a symbolic link with routes (I created a php file because I haven't access to SSH on my server):

<?php
    /*__DIR__ is the directory file, where you save this file.php */
    $mytargetDIR = __DIR__.'/../mi_lar_app/storage';
    $mylinkDIR = __DIR__.'/storage';
        symlink($mytargetDIR,$mylinkDIR);
    echo 'Todo ok/ Symlink process successfully completed';
?>

And important, remember clean cache and routes every changes. If you don't have SSH access:

<?php
    Artisan::call('cache:clear');
    Artisan::call('config:cache');
    Artisan::call('route:cache');
    Artisan::call('view:clear');
      return 'Todo limpio/All is cleaned';
?>

And next this little explanation, some help to me?? :)

Related