PHP | is_readable( ) Function
The is_readable() function in PHP used to check whether the specified file exists and is readable or not. The name of the file is sent as a parameter to the is_readable() function and it returns True if the file exists and is readable.
is_readable() function returns False for streams, for example, php://stdin.
is_readable() function can also be used with some URL wrappers such as file: // ,http:// ,ftp:// ,php:// in PHP 5.0.0.
Syntax:
is_readable($file)
Parameters Used:
The is_readable() function in PHP accepts only one parameter.
- file : It is a mandatory parameter which specifies the file.
Return Value:
It returns True if the file or directory specified exists and is readable otherwise it returns False.
Exceptions:
- An E_WARNING is emitted on failure.
- The result of this function are cached and therefore the clearstatcache() function is used to clear the cache.
Below programs illustrate the is_readable() function.
Program 1
<?php $myfile = "gfg.txt"; // checking whether file is readable or not if (is_readable($myfile)) { echo '$myfile is readable'; } else { echo '$myfile is not readable'; } ?> |
Output:
gfg.txt is readable
Program 2
<?php $myfile = "gfg.txt"; // checking whether file is readable or not if (is_readable($myfile)) { echo '$myfile is readable'; // displaying contents of the uploaded file echo "Contents of the file are :\n"; readfile($myfile); } else { echo '$myfile is not readable'; } ?> |
Output:
gfg.txt is readable Contents of the file are : Portal for geeks!
Program 3
<?php $permissions = fileperms("gfg.txt"); $permvalue = sprintf("%o", $permissions); // Clearing the File Status Cache clearstatcache(); if(is_readable("gfg.txt")) { echo("File is Readable and File Permissions are : $permvalue)"); } else{ echo("File is Not Readable and File Permissions are : $permvalue)"); } // Clearing the File Status Cache clearstatcache(); ?> |
Output:
File is Readable and File Permissions are : 0644
Related Article: PHP | is_writable() Function
Reference:
http://php.net/manual/en/function.is-readable.php
Recommended Posts:
- PHP | SplFileInfo isReadable() Function
- How to call a function that return another function in JavaScript ?
- How to get the function name inside a function in PHP ?
- How to get the function name from within that function using JavaScript ?
- PHP | Ds\Map xor() Function
- D3.js | d3.max() function
- PHP | each() Function
- D3.js | d3.min() function
- PHP | Ds\Set add() Function
- PHP | pow( ) Function
- PHP | Ds\Map put() Function
- PHP | Ds\Set xor() Function
- CSS | rgb() Function
- PHP | min( ) Function
- PHP | key() Function
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.



