How can the use of relative and absolute paths affect the functionality of file_exists in PHP?
When using the file_exists function in PHP, the choice between relative and absolute paths can affect its functionality. Relative paths are based on the current working directory, which may change depending on where the script is executed from. Absolute paths, on the other hand, provide a fixed reference to the file's location on the server. To ensure consistent results, it is recommended to use absolute paths when checking for file existence with file_exists.
// Using absolute path to check if a file exists
$file_path = '/var/www/html/example.txt';
if (file_exists($file_path)) {
echo "File exists!";
} else {
echo "File does not exist.";
}