Definition and usage
The Fpassthru () function outputs all the remaining data at the file pointer.
The function reads the given file pointer from the current location to EOF and writes the result to the output buffer.
Grammar
Fpassthru (file)
| Parameters |
Description |
| File |
Necessary. Specifies the open file or resource to read. |
Description
If an error occurs, Fpassthru () returns false. otherwise fpassthru () returns the number of characters read from file and passed to the output.
The file pointer must be valid and must point to a file that was successfully opened by fopen () or Fsockopen () (but not yet fclose () closed).
Hints and Notes
Tip: If you have already written data to a file, you must call Rewind () to point the file pointer to the file header.
Tip: If you are not modifying the file and not retrieving it at a specific location, just want to download the contents of the file to the output buffer, you should use ReadFile (), which eliminates the fopen () call.
Note: When using Fpassthru () for binary files in a Windows system, be sure to append B to the mode when you open the file with fopen () to open the file in binary mode. Encourage the use of the B flag when working with binaries, even if the system does not require it, to make the script more portable.
Example Example 1
<?php$file = fopen ("Test.txt", "R");//reads the first line fgets ($file);//sends the remainder of the file to the output cache echo fpassthru ($file); fclose ($file); >
Output:
There is three lines in the this file. The last line.59
Note: 59 indicates the number of characters passed.
Example 2
Dump the index page of the WWW server:
<?php$file = fopen ("http://www.example.com", "R"); Fpassthru ($file);? >
PHP Fpassthru () function