admin管理员组文章数量:1418139
I have stored my images in following storage directory:
storage\app\images\
I now need to make this directory publicly accessible.
I stored and created the 'image disk' as follows:
in my controller:
Storage::makeDirectory('images');
Storage::disk('images')->put($imagename, $image);
Then in my config/filesystems i created another disk:
'images' => [
'driver' => 'local',
'root' => storage_path('app/images'),
'url' => env('APP_URL') . '/storage',
'visibility' => 'public',
],
there is already a symlink to the storage/app/public. How do I now make the new directory public.
I tried accessing the image like this:
<img src="{{url('storage/app/images/image.jpeg')}}">
It gave error message image not found.
I also tried to manually create a link:
ln -s storage/app/images public/storage/app/images
EDIT:
Please note that for reason beyond this question, I cannot store my images in:
storage/app/public
The only directory available to me is:
storage\app\images\
So the issue is how to make the above directory publicly accessible.
In answer to @skdishansachin my .env has this entry:
FILESYSTEM_DRIVER=local
and in answer to @Hello There
this is the error;
404 Not Found
https://testSite/storage/app/images/image.jpeg
I have stored my images in following storage directory:
storage\app\images\
I now need to make this directory publicly accessible.
I stored and created the 'image disk' as follows:
in my controller:
Storage::makeDirectory('images');
Storage::disk('images')->put($imagename, $image);
Then in my config/filesystems i created another disk:
'images' => [
'driver' => 'local',
'root' => storage_path('app/images'),
'url' => env('APP_URL') . '/storage',
'visibility' => 'public',
],
there is already a symlink to the storage/app/public. How do I now make the new directory public.
I tried accessing the image like this:
<img src="{{url('storage/app/images/image.jpeg')}}">
It gave error message image not found.
I also tried to manually create a link:
ln -s storage/app/images public/storage/app/images
EDIT:
Please note that for reason beyond this question, I cannot store my images in:
storage/app/public
The only directory available to me is:
storage\app\images\
So the issue is how to make the above directory publicly accessible.
In answer to @skdishansachin my .env has this entry:
FILESYSTEM_DRIVER=local
and in answer to @Hello There
this is the error;
404 Not Found
https://testSite/storage/app/images/image.jpeg
Share
Improve this question
edited Jan 31 at 11:15
temple
asked Jan 31 at 8:48
templetemple
231 silver badge3 bronze badges
4
- Hi, did u run the comand: "php artisan storage:link" ? btw u can follow the Laravel docs for your version here: laravel/docs/6.x/filesystem#obtaining-disk-instances If there is something that it dosent works u following the docs, say the specific step that givs u the error and we will see it together – Hello There Commented Jan 31 at 9:26
- Can you share your .env file – skdishansachin Commented Jan 31 at 10:51
- hi @skdishansachin- i replied to your question above. my env has FILESYSTEM_DRIVER=local – temple Commented Jan 31 at 11:10
- hi @HelloThere. Thanks for answer. I replied to your question in main body of question. I did read docs but they do not provide answer if i want to store images outside of storage/app/public – temple Commented Jan 31 at 11:12
1 Answer
Reset to default 0Sorry for the delay in my response. I am using Laravel 11 in a project, but from what I remember and have seen in the documentation, the way to register disks for file uploads in a Laravel project has not changed.
1. Create the Laravel Disk
In the config/filesystems.php
file, create the disk you want:
In this case, I am creating the FAQs disk, but as you requested, it is outside the "storage/app/public" folder. In this case, it will be in "storage/app/faqs".
return [
'disks' => [
'faqs' => [
'driver' => 'local',
'root' => storage_path('app/faqs'),
'url' => env('APP_URL') . '/faqs',
'visibility' => 'public',
],
],
];
2. Add the Symbolic Link at the End of the config/filesystems.php
Finally, you need to establish the symbolic link so that Laravel registers it when the command is executed.
'links' => [
public_path('storage') => storage_path('app/public'),
public_path('faqs') => storage_path('app/faqs'), // Add yours here, important to establish the same file hierarchy as before
],
3. Execute the Laravel Command
Now, execute the following command:
php artisan storage:link
This should generate the symbolic link to the new disk created in "storage". In this case, we have created a disk at the path storage/app/faqs
.
本文标签: Laravel Make Images Stored in alternative Storage Folder Publicly AccessibleStack Overflow
版权声明:本文标题:Laravel: Make Images Stored in alternative Storage Folder Publicly Accessible - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745274038a2651070.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论