What is the difference between file_exists and is_readable in PHP?
The main difference between `file_exists` and `is_readable` in PHP is that `file_exists` checks if a file or directory exists at the specified path, while `is_readable` checks if a file exists and is readable. Therefore, `file_exists` will return true for both files and directories, while `is_readable` will only return true for files that are readable.
// Check if a file exists and is readable
$file_path = 'example.txt';
if (file_exists($file_path) && is_readable($file_path)) {
echo "File exists and is readable.";
} else {
echo "File does not exist or is not readable.";
}
Keywords
Related Questions
- What is the significance of avoiding special characters, such as "ß", in PHP and SQL code?
- Are there any potential security risks or performance implications to consider when using sessions in PHP to manage data across multiple pages?
- What are the potential causes of DLL errors when running PHP scripts through php.exe?