PHP fpassthru( ) Function Last Updated : 11 Jul, 2025 Comments Improve Suggest changes Like Article Like Report 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. file: It is a mandatory parameter which specifies the file. Return Value: It returns the number of characters passed on success or FALSE on failure. Exceptions The file should be opened in binary mode while using the fpassthru() function on a binary file on Windows. rewind() function should be called to set the file pointer to the beginning of the file if you have already written to the file. the readfile() function should be used if you want to dump the contents of a file to the output buffer without modifying it. Below is the implementation of fpassthru() function. Suppose a file gfg.txt contains the following content : Geeksforgeeks Portal for Geeks! Program 1: php <?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 <?php $myfile = fopen("http://www.geeksforgeeks.com", "rb"); // dumping index page of the server fpassthru($myfile); ?> Reference : https://www.php.net/manual/en/function.fpassthru.php Comment S Shubrodeep Banerjee Follow 0 Improve S Shubrodeep Banerjee Follow 0 Improve Article Tags : Misc Web Technologies PHP PHP-file-handling PHP-function +1 More Explore PHP Tutorial 8 min read BasicsPHP Syntax 4 min read PHP Variables 5 min read PHP | Functions 8 min read PHP Loops 4 min read ArrayPHP Arrays 5 min read PHP Associative Arrays 4 min read Multidimensional arrays in PHP 5 min read Sorting Arrays in PHP 4 min read OOPs & InterfacesPHP Classes 2 min read PHP | Constructors and Destructors 5 min read PHP Access Modifiers 4 min read Multiple Inheritance in PHP 4 min read MySQL DatabasePHP | MySQL Database Introduction 4 min read PHP Database connection 2 min read PHP | MySQL ( Creating Database ) 3 min read PHP | MySQL ( Creating Table ) 3 min read PHP AdvancePHP Superglobals 6 min read PHP | Regular Expressions 12 min read PHP Form Handling 4 min read PHP File Handling 4 min read PHP | Uploading File 3 min read PHP Cookies 9 min read PHP | Sessions 7 min read Like