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

phpis_readable(string $filename): bool

Example

Let's check the accessibility of the file 'test.txt':

php<?php
  $res = is_readable('test.txt');
  var_dump($res);
?>

Code execution result (if the file exists and is readable):

phptrue

Example

Let's check the accessibility of a non-existent file:

php<?php
  $res = is_readable('nonexistent_file.txt');
  var_dump($res);
?>

Code execution result:

phpfalse

Example

Let's check the accessibility of a file with an absolute path:

php<?php
  $res = is_readable('/var/www/html/test.txt');
  var_dump($res);
?>

Code execution result (if the file exists and is readable):

phptrue

See Also

  • the is_writable function,
    which checks write capability
  • the is_executable function,
    which checks execution capability
  • the chmod function,
    which changes access permissions