PHP » I/O » is_readable()

Syntax:
bool is_readable(string filename)
filename
The name of the file to check.

Returns whether a file is readable.

This function returns TRUE if PHP has read access to a specified file and FALSE if it does not. If the file does not exist FALSE is also returned.

Examples

Code:
<?php

$filename = "log.txt";

if (is_readable($filename)) {
   print "File is readable";
   $logfile = fopen($filename, "r");
} else {
   print "Access denied to $filename";
}

?>
Output:
File is readable
Explanation:

If the file does not exist, or user privileges of PHP do not permit reading of the file, the file cannot be opened.

See Also: