- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
is_readable() function in PHP
The is_readable() function checks whether a file is readable. The function returns TRUE if the file or directory exists and is readable. It returns FALSE if the file or directory does not exist.
Syntax
is_readable(file_path)
Parameters
file_path − Specify the file to check.
Return
The is_readable() function returns TRUE if the file or directory exists and is readable. It returns FALSE if the file or directory does not exist.
Example
<?php $file_path = "new.txt"; if(is_readable($file_path)) { echo ("Readable!"); } else { echo ("Not readable!"); } ?>
Output
Not readable!
Let us see another example that also reads the file if it is readable.
We have a file “demo.txt” with the following content.
This is demo text in demo file!
The following is the code that checks whether the file is readable or not. If it is readable, then the file content is also displayed.
Example
<?php $file_path = "demo.txt"; if(is_readable($file_path)) { echo ("Readable!"); echo ("Reading file: "); readfile($file_path); } else { echo ("Not readable!"); } ?>
Output
Not readable!
Advertisements