How to determine file exist in public directory for Laravel 5.2

Viewed 11128

I have some image files in public/image directory, so I want to determine if a file exist in that directory before I save a new file. How to determine if a file exist?

4 Answers

file_exists(public_path($name)

here is my solution to check if file exists before downloading file.

if (file_exists(public_path($name)))
    return response()->download(public_path($name));
Related