$filename = 'example.txt'; $path = '/path/to/directory/'; if (is_file($path . $filename)) { echo "The file exists"; } else { echo "The file does not exist"; }
$directory = '/path/to/directory/'; $files = scandir($directory); foreach ($files as $file) { $path = $directory . $file; if (is_file($path)) { echo "$path is a file\n"; } else { echo "$path is not a file\n"; } }In this example, we are using the scandir() function to return an array of files and directories in the "/path/to/directory/" directory. We then loop through each file in the directory and check if it is a file using the isFile() function. The isFile() function is part of the PHP core, and doesn't require any external package or library.