PHP Function Reference

PHP is_readable() Function



The PHP is_readable() function checks whether a file exists and is readable.

Note: The results of this function are cached. Use clearstatcache() function to clear the cache.

Syntax

is_readable(filename)

Parameters

filename Required. Specify the path to the file to check.

Return Value

Returns true if the file or directory specified by filename exists and is readable, otherwise returns false.

Note: This function may return true for directories. Use is_dir() to distinguish file and directory.

Exceptions

Upon failure, an E_WARNING is thrown.

Example:

Lets assume that we have a file called test.txt in the current working directory. The example below demonstrates on using this function to check whether a file exists and is readable.

<?php
$file1 = 'test.txt';
$file2 = 'demo.txt';

//checking if $file1 is readable
if(is_readable($file1)) {
  echo "The file $file1 is readable.\n";
} else {
  echo "The file $file1 is not readable.\n";
}

//checking if $file2 is readable
if(is_readable($file2)) {
  echo "The file $file2 is readable.\n";
} else {
  echo "The file $file2 is not readable.\n";
}
?>

The output of the above code will be:

The file test.txt is readable.
The file demo.txt is not readable.

❮ PHP Filesystem Reference