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

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


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.');

}



Hardik Savani
My name is Hardik Savani. I'm a full-stack developer, entrepreneur and owner of Aatman Infotech. I live in India and I love to write tutorials and tips that can help to other artisan. I am a big fan of PHP, Javascript, JQuery, Laravel, Codeigniter, VueJS, AngularJS and Bootstrap from the early stage.
***Do you want me hire for your Project Work? Then Contact US.