Get files or images from outside the project folder using storage in laravel, we will change to a custom image file path in the filesystem configuration.
I want to get files from outside applications from another directory, also i want to get a file using a storage public disk.
My File Located
My image file is located in the below-given file path, So I will put this file path in the filesystem configuration.
"/var/www/html/images/logo.png"
Change Path In Config
I put this path in the filesystems.php
config/filesystems.php'disks' => [ 'local' => [ 'driver' => 'local', 'root' => storage_path('app'), ], 'public' => [ 'driver' => 'local', 'root' => '/var/www/html/images/', // CUSTOME IMAGES FILE TO OUTSIDE PROJECT 'url' => '/var/www/html/images/', // CUSTOME IMAGES FILE TO OUTSIDE PROJECT 'visibility' => 'public', ], 's3' => [ 'driver' => 's3', 'key' => env('AWS_ACCESS_KEY_ID'), 'secret' => env('AWS_SECRET_ACCESS_KEY'), 'region' => env('AWS_DEFAULT_REGION'), 'bucket' => env('AWS_BUCKET'), 'url' => env('AWS_URL'), 'endpoint' => env('AWS_ENDPOINT'), 'use_path_style_endpoint' => env('AWS_USE_PATH_STYLE_ENDPOINT', false), ], ],
Basic Usage
Now my storage public disk file path is "/var/www/html/images", So when I pass the image name as in the below given example, the image will fetch from the given file path outside the project.
Storage::disk('public')->url('logo.png');
We always thanks to you for reading our blogs.
Dharmesh Chauhan
(Swapinfoway Founder)Hello Sir, We are brothers origin from Gujarat India, Fullstack developers working together since 2016. We have lots of skills in web development in different technologies here I mention PHP, Laravel, Javascript, Vuejs, Ajax, API, Payment Gateway Integration, Database, HTML5, CSS3, and Server Administration. So you need our service Please Contact Us
Haresh Chauhan
(Co-Founder)We Are Also Recommending You :
- What are accessors and mutators In Laravel
- Laravel 6 Image Upload Tutorial
- Laravel Scope With Example Usage
- MongoDB Database Connection In Laravel
- Arr::collapse() | Laravel Helper Function
- Laravel 56 Login and Logout
- could not find driver (SQL: select count(*) as aggregate from "users" where "email" = admin@gmail.com)
- Laravel-9 Multi Authentication Guard Passport API Example
- Firebase Dynamic Links Shorten URL PHP Function
- How To Generate Image From HTML Using Snappy In Laravel 9