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
Parameter | Is Required | Description |
---|---|---|
file | Required. | 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//w ww . j a v a 2s .co m
$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:
/* w w w . ja va2 s .c om*/
<?php
$file = fopen("http://www.google.com","r");
echo fpassthru($file);
?>
The code above generates the following result.