PHP fpassthru() Function

PHP fpassthru Function


Definiition :

The PHP fpassthru() function reads from the current position in a file until EOF, and then writes the result to the output buffer.

Call rewind() to reset the file pointer to the beginning of the file if you have already written data to the file.

To dump the contents of a file to the output buffer, without first modifying it or seeking to a particular offset, you may want to use the readfile().

Note: When using this function on a binary file on Windows systems, the file should be opened in binary mode.

Syntax

   fpassthru(file)

Parameter
Parameter Description
file Required. Specifies the open file to read from

Example: fpassthru() example

Lets assume that we have a file called demo.txt. This file contains following content:

This is a test file.
It contains dummy content
.


In the example below, the first line from the file is read using fgets() function. Then the remaining content of the file is written to the output buffer using fpassthru() function.

 Output :  this another line of this file.31