mDelshad's avatar

how to access a file in the local disk?

i'm upload images with this code:

$path = $request->file('image')->store('documents');

and i can get file address with return $path

but when i open the link in browser, error 404 displayed

The image is uploaded correctly! I also executed this command php artisan storage:link

in public folder and this directory storage just avatar folder has been created , But the folder documents will not be created

0 likes
4 replies
Snapey's avatar

A path is not a URL. They are not the same. One (URL) is a resource on the internet, and the path is a place within your filesystem.

The two are not interchangeable.

From the docs

By default, the store method will generate a unique ID to serve as the file name. The file's extension will be determined by examining the file's MIME type. The path to the file will be returned by the store method so you can store the path, including the generated file name, in your database.

So without any further instruction, the file will be stored with a random filename in your default file location, and the documents folder there.

If you have not changed it, the default disk is local and this is configured as storage/app

So your file (if one was attached) should be in storage/app/documents/...randomfilename...

This location should not be accessible to the outside world.

If you want to allow users to see/download this file, you need to store it on the public disk.

1 like
Snapey's avatar

If you want to serve the content through your website then yes, it needs to be public

Please or to participate in this conversation.