if (file_exists('myfile.txt')) { echo 'The file exists!'; } else { echo 'The file does not exist!'; }
if (file_exists('mydir')) { echo 'The directory exists!'; } else { echo 'The directory does not exist!'; }
if (file_exists('/home/user/myfile.txt')) { echo 'The file exists!'; } else { echo 'The file does not exist!'; }The `file_exists()` function is part of the PHP core, so it does not require any special package or library.