How to check if file exists or not in Laravel?

Today now in this post i would like to show you How to check if file exists or not in Laravel? Now days laravel framework is a popular framework in PHP Language. So, if we need to check if file is exists or not in the given path then we can check this easily. Normally we always need to check if the image exists, check if pdf file exists, check if docs exists or not etc. So here I will give you two way to check file is Exists or not. Here one is by using file_exists() and second one is by using File facade of laravel.

it’s better if you prefer File facade example.

So, let’s see and implement it:

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

Read Also : How to convert Object into Array in PHP?

Thanks for read. I hope it help you. For more you can follow us on facebook.