PHP fpassthru () function
Definition and Usage
fpassthru () function to start reading all data from the open file's current position until the end of the file (EOF), write the results to the output buffer.
This function returns the number of characters transmitted, if failed to return FALSE.
grammar
参数 | 描述 |
---|---|
file | 必需。规定要读取的打开文件或资源。 |
Tips and Notes
Note: When using fpassthru in Windows system binaries () function, keep in mind, you must open the file in binary mode.
Tip: If you have to write data to a file, you must call rewind () to the file pointer to the file header.
Tip: If you want the contents of the file to the output buffer, but not modify it, use the readfile () function instead, which eliminates the need for fopen () call.
Example 1
$file = fopen("test.txt","r");
// Read first line
fgets($file);
// Send rest of the file to the output buffer
echo fpassthru($file);
fclose($file);
?>
The code above will output:
This is the last line.59
59 indicates the number of characters to be delivered.
Example 2
Dump www server index page:
$file = fopen("http://www.example.com","r");
fpassthru($file);
?>
Complete PHP Filesystem Reference Manual