kundefine's avatar

Upload File to disk

In public disk I don't understand what's is the difference between "root" and "url" in disk config. I know that "root" is the path where i will upload my file but what about "url" and why i need it.

        'public' => [
            'driver' => 'local',
            'root' => storage_path('app/public'), // where i want to upload my file
            'url' => env('APP_URL').'/storage', // why i need url over here
            'visibility' => 'public',
        ],

0 likes
2 replies
JohnBraun's avatar
Level 33

The 'url' property is used when you generate a URL for a file you've stored.

So, if the APP_URL is set to "http://your-domain.com":

$url = Storage::disk('public')->url('test.txt');

// returns http://your-domain.com/storage/test.txt

Now, if you wanted to store them elsewhere, you need to adjust the way the URL is generated.

Please or to participate in this conversation.