PHP readfile()Function
Complete PHP Filesystem Reference
Definition and Usage
The readfile() function reads a file and writes it to the output buffer.
If successful, the function returns the number of bytes read from the file. If it fails, the function returns FALSE along with an error message. You can hide the error output by adding an '@' in front of the function name.
Syntax
readfile(filename,include_path,context)
| Parameter | Description |
|---|---|
| filename | Required. Specifies the file to be read. |
| include_path | Optional. Set this parameter to '1' if you also want to search for the file in the include_path (in php.ini). |
| context | Optional. Specifies the environment of the file handle. Context is a set of options that can modify the behavior of the stream. |
Tips and Notes
Tip:If "fopen wrappers" have been enabled in the php.ini file, you can use a URL as the filename in this function.
Examples
<?php
echo readfile("test.txt");
?>
echo readfile("test.txt");
?>
The code above will output:
There are two lines in this file.
This is the last line.
57
This is the last line.
57
Complete PHP Filesystem Reference Other Extensions