The fpassthru Function
The fpassthru
function outputs all data from a file, starting from the current position of the file pointer until the end. The function accepts one parameter - a pointer to a file that must be opened for reading. After execution, the function returns the number of bytes output or false
in case of an error.
Syntax
fpassthru(resource $handle): int|false
Example
Output the contents of the file 'data.txt':
<?php
$file = fopen('data.txt', 'r');
fpassthru($file);
fclose($file);
?>
Example
Check the number of bytes output:
<?php
$file = fopen('data.txt', 'r');
$bytes = fpassthru($file);
echo "Bytes output: $bytes";
fclose($file);
?>
Example
Try using fpassthru after partially reading the file:
<?php
$file = fopen('data.txt', 'r');
fgets($file); // read the first line
fpassthru($file); // output the remainder of the file
fclose($file);
?>