The file_exists() function is a built-in function in PHP that checks whether a file or directory exists or not. The function returns true if the file or directory exists, and false if it does not exist or if there has been some error.
Code Examples:
Example 1: Check if a file exists:
$file_path = "C:/Users/myfile.txt";
if (file_exists($file_path)) { echo "The file exists!"; } else { echo "The file does not exist or there has been some error."; }
Example 2: Check if a directory exists:
$dir_path = "C:/Users/my_folder";
if (file_exists($dir_path) && is_dir($dir_path)) { echo "The directory exists!"; } else { echo "The directory does not exist or there has been some error."; }
Package Library:
The file_exists() function is included in the core PHP library, and therefore it does not require any external package or library.
PHP file::exists - 27 examples found. These are the top rated real world PHP examples of file::exists extracted from open source projects. You can rate examples to help us improve the quality of examples.