The fpassthru() function reads all data starting from the current position of the open file until the end of file (EOF), and writes the result to the output buffer.
This function returns the number of characters passed, or FALSE on failure.
fpassthru(file)
parameter | describe |
---|---|
file | Required. Specifies an open file or resource to read. |
NOTE: When using the fpassthru() function from a binary file on a Windows system, keep in mind that the file must be opened in binary mode.
Tip: If you have written data to the file, you must call rewind() to point the file pointer to the beginning of the file.
Tip: If you just want to output the contents of the file to the output buffer without modifying it, use the readfile() function instead, which saves the fopen() call.
<?php$file = fopen("test.txt","r");// Read first linefgets($file);// Send rest of the file to the output bufferecho fpassthru($file);fclose($file );?>
The above code will output:
There are three lines in this file.This is the last line.59
59 indicates the number of characters passed.
Dump the index page of the www server:
<?php$file = fopen("http://www.example.com","r");fpassthru($file);?>