Skip to content
PHP Logo

How can file_exists() function in PHP be affected by open_basedir restrictions?

When open_basedir restrictions are in place, the file_exists() function in PHP may not be able to access files outside the specified directory restrictions. To solve this issue, you can use the is_file() function instead, which does not check for open_basedir restrictions.

php
$file_path = '/path/to/file.txt';

if (is_file($file_path)) {
    echo "File exists!";
} else {
    echo "File does not exist.";
}