PHP Tutorial - PHP fpassthru() Function






Definition

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

Syntax

PHP fpassthru() Function has the following syntax.

fpassthru(file)

Parameter

ParameterIs RequiredDescription
fileRequired.Open file or resource to read from

Return

This function returns the number of characters passed or FALSE on failure.





Note

When using fpassthru() on a binary file on Windows, remember to open the file in binary mode.

Example


<?php
$file = fopen("test.txt","r");
fgets($file);// Read first line
echo fpassthru($file);// Send rest of the file to the output buffer
fclose($file);
?>

The code above generates the following result.





Example 2

Dump index page of a www server:



<?php
$file = fopen("http://www.google.com","r");
echo fpassthru($file);
?>

The code above generates the following result.