I would like to move one of my files from the storage
file directory in Laravel to the public
file directory in laravel, without changing my file system configuration. Is this possible?
Yes, you can do it with Storage::move and public_path() helper.
Storage::move( 'old/file.jpg', public_path('new/file.jpg') );
Note that old/file.jpg
is relative to your-project/storage/app
, so the file that you want to move would be in your-project/storage/app/old/file.jpg
UPDATE
Still, another approach could be to move/store the file in laravel-project/storage/app/public
.
And then have it accessible in the public directory via a symbolic link.
After that, all the files and directories inside laravel-project/storage/app/public
will be linked to laravel-project/public/storage/
directory.
Then you can access the file by url.
So, to do it in this way, move the file to storage/app/public/ folder:
Storage::move( 'old/file.jpg', 'public/movedfiles/file.jpg' );
Create the symbolic link by this artisan command:
php artisan storage:link
Then you can access the file by url:
<a href='http://your-domain/storage/movedfiles/file.jpg'>file.jpg</a>
or in blade
<a href='{{ asset('storage/movedfiles/file.jpg') }}'>file.jpg</a>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With