How to check if file exists or not in Laravel 5?

By Hardik Savani | April 23, 2016 | | 5383 Viewer | Category : Laravel


Share this post:

Nowdays laravel framework is popular framework in PHP Language. So, if you required to check if file is exists or not in given path then you can check eisily. Normally we always need to check if image exists, check if pdf file exists, check if docs exists or not etc. I give you two way to check file is Exists or not. one using file_exists() and second one using File facade of laravel 5. it's better if you preffer File facade example. So, let's see and implement:

Example 1:

if(file_exists(public_path('images/1461177230.jpg'))){

dd('File is exists.');

}else{

dd('File is not exists.');

}

Example 2:

if(File::exists(public_path('images/1461177230.jpg'))){

dd('File is exists.');

}else{

dd('File is not exists.');

}