Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

randm's avatar
Level 6

How to access uploaded files?

I am trying to allow my users to upload files.

I am using the following code to save the uplaoded file

$file->store('uploads', config('filesystems.default'))

The files are getting uploaded to storage/app/uploads as expected.

But I am unable to access the uploaded files.

In my views I am using the following to show the URL for the attachment

{{ asset('storage/uploads/d4PH5XJ1wU165nN5EQXzDcxBCvgmAn5p1uRGIrCJ.txt') }}

the above code returns the following

http://domain.com/storage/uploads/d4PH5XJ1wU165nN5EQXzDcxBCvgmAn5p1uRGIrCJ.txt

I ran the php artisan storage:link command which created the symbolic link. However, that link returns the following error

NotFoundHttpException in RouteCollection.php line 179:

How can I correctly expose the uploaded file to the public?

0 likes
2 replies
Snapey's avatar

The files need to be in the storage/app/public folder to use the symlink (or create your own link)

randm's avatar
Level 6

@Snapey That indeed was the problem. Thank you!

I need to store 'uploads/filename.extension' into the database. I am using the store method on the file to move the file like so

$uplodedFile = $file->store('public/uploads', config('filesystems.default'));

However, the variable $uplodedFile returns public/uploads/filename.extension. Is there a different method to use that store so I can easily return /uploads/filename.extension instead of public/uploads/filename.extension

The problem with storing public/uploads/filename.extension in the database is that the method asset('storage/' + $filename) will render the url to this domain.com/storage/public/uploads/filename.extension instead of domain.com/storage/uploads/filename.extension

Please or to participate in this conversation.