$file = '/path/to/file.txt'; if (file_exists($file)) { echo "The file '{$file}' exists!"; } else { echo "The file '{$file}' does not exist."; }
$dir = '/path/to/directory'; if (file_exists($dir) && is_dir($dir)) { echo "The directory '{$dir}' exists!"; } else { echo "The directory '{$dir}' does not exist."; }This example checks if the directory `/path/to/directory` exists and is a valid directory. These functions are part of the PHP core library and do not require a separate package or library.