ONYX
ONYX

Reputation: 5859

Laravel Storaget get file contents

I want to know if you do the following in my code below how do you check if the file exists e.g

{
    $file = Storage::disks('local')->get($file);
    // then test if $file exists
}

Upvotes: 0

Views: 2633

Answers (2)

Prashant Barve
Prashant Barve

Reputation: 4315

You can check the existence of the file with the code below for your local storage,

$file_exists = Storage::disk('local')->exists($file);

You can read more about storage on Laravel Document at Laravel Filesystem. Note: in the document you will check disk('s3'). It depends on what connection we are using defined in config/filesystem.php(the configuration file for the filesystem in laravel).

OR simply you can use check the condition by

if(Storage::disk('local')->exists($file)) { 

}

It will also work for you.

Upvotes: 5

fubar
fubar

Reputation: 17378

There's a clear example in the docs, if you take a look.

$exists = Storage::disk('s3')->exists('file.jpg');

Upvotes: 2

Related Questions