PHP | is_readable( ) Function
Last Updated :
06 Jun, 2018
Improve
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:
php
Output:
php
Output:
php
Output:
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.
- 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.
<?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';
}
?>
gfg.txt is readableProgram 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';
}
?>
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();
?>
File is Readable and File Permissions are : 0644Related Article: PHP | is_writable() Function Reference: http://php.net/manual/en/function.is-readable.php