How do you get the path to the Laravel Storage folder?
In Laravel 3, call path('storage')
.
In Laravel 4, use the storage_path()
helper function.
Get path to file in storage
There is no correct way to do this; because it should not be done. The Storage is an opaque system to talk to different storage systems; as such there is no api to get the backing file path. As an example, that wouldn't work with Amazon S3. The only path your application knows about is the string you send to the Storage facade to work with the file, there are no guarantees that this string is used to generate the filename when the storage system stores the file.
There are some hacks you can use that works for the local disk, but those are not available for the Storage system in general. Using these solutions means that you'll limit yourself to only use the local disk; this will cause you troubles when you need to scale out and add another server. You'll then have two servers with two separate local disks, with separate content.
The correct way to work with the files, that will work for all configurations, is to get the file content (Storage::get
), do the modifications (including storing them in a temporary file) and then write back the new file content (Storage::set
).
If you're really sure that you will only ever use the local filesystem, use the File facade instead of the Storage facade. I'm unable to find any documentation for this, only the interface it exposes.
Reference: https://github.com/laravel/framework/issues/13610
Access to the storage folder in Laravel is impossible
Solution 1: create a symlink
you can not access files located in storage
directory directly via URL! Only files located in public
folder would be available publicity. So you should make a symlink in public folder pointing the directory or file (within storage folder) you want to share. Take a look at this answer
Solution 2:
Just upload the files in public
folder!
How to retrieve file from Laravel storage subfolder?
TL/DR
Storage::disk('public')->get('block/3.jpg');
Explanation
The problem is you're putting storage
in the path for some reason. It's not necessary and is leading to the wrong path being built.
Take a look at the default filesystems config:
'disks' => [
'local' => [
'driver' => 'local',
'root' => storage_path('app'),
'throw' => false,
],
'public' => [
'driver' => 'local',
'root' => storage_path('app/public'),
'url' => env('APP_URL').'/storage',
'visibility' => 'public',
'throw' => false,
],
The root
is what is useful to see here. storage_path()
returns the full path to the storage folder. So something like storage_path('folder_1')
-> /home/user/project/storage/folder_1
.
The local
disk is the default, so just doing Storage::get()
will use it automatically.
You're using the public
disk, so the actual location of these files is storage/public
(symlinked into public/storage
). This means doing Storage::disk('public')
already begins at /home/user/project/storage/app/public
. Adding storage
again makes the path incorrect.
Using path
may help with future debugging. Storage::disk('public')->path('block/3.jpg') will output the full path, and you can see where it's going wrong. For your code given it would probably show something like /home/user/project/storage/app/public/storage/app/public
.
Related Topics
Download a Facebook Video (.Mp4) Via PHP
Laravel Eloquent How to Get the Minimum Value That Is Not Null
Dompdf Table Fixed Column Width and Break Long Text
How to Get the Path to the Laravel Storage Folder
Getting Data from a Textarea into a Database
How to Increase Maximum Execution Time in Laravel
How to Pass Something With Apostrophe to Json
How to Get Useful Error Messages in PHP
How to Get the Client Ip Address in PHP
Showing All Errors and Warnings
Apache Virtual Host Always Redirecting to /Dashboard
Laravel - How to Join 2 Tables from Different Db Connection
Laravel 5.6 Class App\Http\Controllers\Postcontroller Does Not Exist
How to Properly Encode Utf-8 for JavaScript and Json