In this article, you will learn how to read a file in PHP. The readfile() function in PHP reads a file and writes it to the output buffer.
You can also use the URL to the file in the filename parameter. For this, enable fopen wrappers in the PHP.ini file.
what is the syntax of the READFILE function in php?
readfile(file, include_path, context)
Parameter | Description |
---|---|
file | Required. Specifies the file to read |
include_path | Optional. Set this parameter to TRUE if you want to search for the file in the include_path (in php.ini) as well |
context | Optional. Specifies the context of the file handle. Context is a set of options that can modify the behavior of a stream |
examples of the READFILE function
Example 1. In this example, we read a file.
<?php
echo readfile("test.txt");
?>