The is_readable Function
The is_readable function checks whether the specified file exists
and is readable. The function returns true if the file
exists and is readable, and false otherwise.
The parameter is a file path as a string.
Syntax
is_readable(string $filename): bool
Example
Let's check the accessibility of the file 'test.txt':
<?php
$res = is_readable('test.txt');
var_dump($res);
?>
Code execution result (if the file exists and is readable):
true
Example
Let's check the accessibility of a non-existent file:
<?php
$res = is_readable('nonexistent_file.txt');
var_dump($res);
?>
Code execution result:
false
Example
Let's check the accessibility of a file with an absolute path:
<?php
$res = is_readable('/var/www/html/test.txt');
var_dump($res);
?>
Code execution result (if the file exists and is readable):
true
See Also
-
the
is_writablefunction,
which checks write capability -
the
is_executablefunction,
which checks execution capability -
the
chmodfunction,
which changes access permissions