Skip to content
Advertisement

How to upload files in Laravel directly into public folder?

The server which I’m hosting my website does not support links so I cannot run the php artisan storage:link to link my storage directory into the public directory. I tried to remake the disk configuration in the filesystems.php to directly reference the public folder but it didn’t seems to work either. Is there a way to upload a file using Laravel libraries directly into the public folder or will I have to use a php method? Thanks in advance.

Advertisement

Answer

You can create a new storage disc in config/filesystems.php:

'public_uploads' => [
    'driver' => 'local',
    'root'   => public_path() . '/uploads',
],

And store files like this:

if(!Storage::disk('public_uploads')->put($path, $file_content)) {
    return false;
}
User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement