Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

PHP fpassthru() Function

PHP fpassthru() Function


PHP Filesystem Reference Manual Complete PHP Filesystem Reference Manual


Definition and Usage

The fpassthru() function reads all data from the current position of an open file to the end of file (EOF) and writes the result to the output buffer.

Returns the number of characters passed, or FALSE on failure.

Syntax

fpassthru(file)

Parameters Description
file Required. Specifies the open file or resource to read.

Tips and Notes

**Note:** When using fpassthru() on a binary file on Windows, remember that the file must be opened in binary mode.

**Tip:** If you have already written data to the file, you must call rewind() to move the file pointer to the beginning of the file.

**Tip:** If you only want to output the contents of a file to the output buffer without modifying it, use the readfile() function instead, which saves the fopen() call.


Example 1

The code above will output:

There are three lines in this file.

This is the last line.59

59 indicates the number of characters passed.


Example 2

Dump the index page of a www server:


PHP Filesystem Reference Manual Complete PHP Filesystem Reference Manual