PHP readfile() Function
Definition and Usage
The readfile() function outputs a file.
This function reads a file and writes it to the output buffer.
If successful, it returns the number of bytes read from the file. If failed, it returns false. You can call this function in the form of @readfile() to hide error messages.
Syntax
readfile(filename,include_path,context)
Parameter | Description |
---|---|
filename | Required. Specifies the file to be read. |
include_path | Optional. If you also want to include_path search for files, you can use this parameter and set it to true. |
context | Optional. Specifies the environment for the file handle.Context is a set of options that can modify the behavior of a stream. |
Description
for context Parameter support was added in PHP 5.0.0.
Tips and Comments
Tip:If the 'fopen wrappers' in the php.ini file have been activated, you can use the URL as a filename in this function.
Example
<?php echo readfile("test.txt"); ?>
Output:
There are two lines in this file. This is the last line. 57