ocraftsocial's avatar

Making a uploaded local file shareable to the public

Hey,

I'm trying to make my uploaded files (being uploaded into local folder, not publicly accessed) shareable via a controller, routes and serving a js in the blade view, that doesn't seems to be the way to do it, i'm wondering how is it possible to make a private uploaded file shareable and accessible to everyone after clicking a button...

Can anyone explain the signature function of the url for me? thanks...

0 likes
2 replies
sm3rter's avatar

Actually, the public directory is the only accessible directory in your application, so you shouldn't store private files there. Instead, you can check the available disks in your config/filesystems.php

'disks' => [

    'local' => [
        'driver' => 'local',
        'root' => storage_path('app/private'),
        'serve' => true,
        'throw' => false,
    ],

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

],

The public disk can be accessed through the browser, while local disk remains private.

Check out this example:

use Illuminate\Support\Facades\Storage;

Storage::disk('local')->move(
    from: $source,
    to: $dest
);

For more check out Laravel doc. https://laravel.com/docs/11.x/filesystem

1 like

Please or to participate in this conversation.