Open In App

PHP fpassthru( ) Function

The fpassthru() function in PHP is an inbuilt function which is used to read data from a current position from a specified file until end of file and then write the result to the output buffer. The file which has to be read is sent as a parameter to the fpassthru() function and it returns the number of characters passed on success or FALSE on failure.

Syntax:



int fpassthru ( $file )

Parameters Used:
The fpassthru() function in PHP accepts one parameter.

Return Value:



Exceptions

Below is the implementation of fpassthru() function.

Suppose a file gfg.txt contains the following content :

Geeksforgeeks
Portal for Geeks!

Program 1:




<?php
// opening a file in read only mode
$myfile = fopen("gfg.txt", "rb");
  
// Reading the first line of the file
fgets($myfile);
  
// Sending the rest of the file 
// contents to the output buffer
echo fpassthru($myfile);
  
// closing the file
fclose($myfile);
?>

Output:

Portal for Geeks!17

Note: 17 indicates the number of characters passed.

Program 2:




<?php
$myfile = fopen("http://www.geeksforgeeks.com", "rb");
  
// dumping index page of the server
fpassthru($myfile);
?>

Reference :
http://php.net/manual/en/function.fpassthru.php


Article Tags :