Check if a file exists and is readable in PHP

Description

The following code shows how to check if a file exists and is readable.

Example


<?php/* ww  w  .ja  v a 2 s.c  o  m*/
$filename = 'test.txt';
if (is_readable($filename)) {
    echo 'The file is readable';
} else {
    echo 'The file is not readable';
}
?>

The code above generates the following result.





















Home »
  PHP Tutorial »
    File »




Directory
DirectoryIterator
Drive
File
File Permission
File Read Save
FileSystemIterator
Path
Zip