Reputation: 181
I want to access the file storage/app/15573877669649.jpg
.
$file = $request->file('cover_image');
$fileName = time().rand(111, 9999).".".$file->getClientOriginalExtension();
Storage::disk('local')->put($fileName, file_get_contents($file));
blade.php
file<img src = "{{ URL::to('/').Storage::url($article->coverImage) }}" alt="image">
which returns
http://127.0.0.1:8000/storage/15573877669649.jpg
I have tried to manually put http://127.0.0.1:8000/storage/app/15573877669649.jpg
but it's also not working
Upvotes: 2
Views: 3425
Reputation: 190
By default, Laravel's Storage::('local')
is not accessible from public; the Storage::('public')
is the one will be publish by command php artisan storage:link
So for your sample code, you can do it like this:
Uploading file
$file = $request->file('cover_image');
$fileName = time().rand(111, 9999).".".$file->getClientOriginalExtension();
Storage::disk('public')->put($fileName, file_get_contents($file));
In blade.php file
<img src = "{{ URL::to('/').Storage::disk('public')->url($article->coverImage) }}" alt="image">
// Or simpler
<img src = "{{ asset("/storage/$article->coverImage") }}" alt="image">
More detail of the 'disk' please check config file in /config/filesystems.php
, and refer the the Public Disk section of official document
And, remember to enable the follow symlinks settings in your web server
// Apache:
<Directory>
Options FollowSymLinks
</Directory>
// Nginx:
{
disable_symlinks off;
}
Upvotes: 2
Reputation: 1789
php artisan storage:link
Your files will now be accessible under "/storage/file.jpg"
/
leads to public
/storage/
leads you to storage/app/public
thanks to link
Upvotes: 4