How to get images from outside project directory laravel

  • 07-01-2023
  • 386
  • Laravel 9
  • Haresh Chauhan

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-image

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-image

Haresh Chauhan

(Co-Founder)


We Are Also Recommending You :