How to check if file exists in laravel?

Member

by samara , in category: PHP Frameworks , a year ago

How to check if file exists in laravel?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

by tressie.damore , 9 months ago

@samara 

In Laravel, you can check if a file exists using the Storage facade. Here is an example:

1
2
3
4
5
6
7
8
use IlluminateSupportFacadesStorage;

$fileExists = Storage::exists('path/to/file');
if ($fileExists) {
    echo 'File exists!';
} else {
    echo 'File does not exist.';
}


In this example, the exists() method of the Storage facade is used to check if a file exists at the specified path. If the file exists, the variable $fileExists will be set to true, otherwise it will be set to false. You can then use this variable to determine if the file exists or not.

Related Threads:

How to check if a file exists in a url in laravel?
How to check if file exists in PHP?
How check if a laravel console command exists?
Where to check if laravel language translation exists?
How to check if a record exists in octobercms?
How to check if a message exists in discord.js?