PHP SplFileObject fpassthru() Function Last Updated : 28 Apr, 2025 Comments Improve Suggest changes Like Article Like Report The SplFileObject::fpassthru() is an inbuilt function in PHP that is used to output the contents of a file to the output buffer, typically the browser, without reading the entire file into memory. It allows you to efficiently stream the contents of a file in smaller chunks, which is particularly useful for working with large files. Syntax: public SplFileObject::fpassthru(): intParameters: This function does not have any parameters. Return Value: This function returns the number of characters from the buffer. Program 1: The following program demonstrates SplFileObject::fpassthru() function. Note: Before running this program save this file as "data.txt" John,Doe,25Jane,Smith,30Alice,Johnson,28 PHP <?php $file = new SplFileObject('data.txt', 'r'); $file->fpassthru(); ?> Output: John,Doe,25Jane,Smith,30Alice,Johnson,28Program 2: The following program demonstrates SplFileObject::fpassthru() function. PHP <?php $filePath = 'output.txt'; // Check if the file exists if (file_exists($filePath)) { $file = new SplFileObject($filePath, 'r'); // Output the file content to the browser $file->fpassthru(); } else { // Handle the case when the file doesn't exist echo "File not found."; } ?> Output: hey Geeks for Geeks Reference: https://www.php.net/manual/en/splfileobject.fpassthru.php Comment More infoAdvertise with us Next Article PHP SplFileObject fpassthru() Function N neeraj3304 Follow Improve Article Tags : PHP PHP-function PHP-SPL-Functions Similar Reads PHP | SplFileObject fstat() Function The SplFileObject::fstat() function is an inbuilt function of Standard PHP Library (SPL) in PHP which is used to give the information of the file. Syntax: array SplFileObject::fstat( void ) Parameters: This function does not accept any parameter. Return values: This function returns an array which c 1 min read PHP SplFileObject fflush() Function The SplFileObject::fflush() function is an inbuilt function in the Standard PHP Library (SPL) in PHP that is used to flush the output buffer of the file. Syntax: public SplFileObject::fflush():boolParameter:Â This function does not accept any parameters. Return Value:Â The SplFileObject::fflush() func 2 min read PHP | SplFileObject fgetss() Function The SplFileObject::fgetss() function is an inbuilt function of Standard PHP Library (SPL) in PHP which is used to get line from file and strip HTML tags.Syntax:Â Â string SplFileObject::fgetss( $tags) Parameters: This function accept only one parameter $tags an optional parameter to specify tags whic 1 min read PHP | SplFileObject ftruncate() Function The SplFileObject::ftruncate() function is an inbuilt function of Standard PHP Library (SPL) in PHP which is used to truncates the file size in bytes. Syntax: bool SplFileObject::ftruncate( $length ) Parameters: This function accept single parameter $length which specified the length of truncate of 1 min read PHP | SplFileObject fputcsv() Function The SplFileObject fputcsv() function is an inbuilt function of Standard PHP Library (SPL) in PHP which is used write a field array as a CSV line. Syntax: string SplFileObject::fputcsv() Parameters: This function accept four parameters one is mandatory and three are optional. $fields: Specifies the a 1 min read Like