PHP | SplFileObject ftruncate() Function Last Updated : 20 Dec, 2018 Comments Improve Suggest changes Like Article Like Report 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 the file. Return values: This function returns True on success or False on failure. Below Programs illustrate the SplFileObject ftruncate() function in PHP: Program 1: php <?php // Create a file named "gfg.txt" which // containing data "GeeksforGeeks" $gfg = new SplFileObject("gfg.txt", "w+"); $gfg->fwrite("GeeksforGeeks"); // Truncate file $gfg->ftruncate(8); // Rewind and reading data from file $gfg->rewind(); // Print result after truncate echo $gfg->fgets(); ?> Output: Geeksfor Program 2: php <?php // Create an Array $GFG = array( "dummy.txt", "gfg.txt", "frame.txt" ); // Creating Spl Object foreach ($GFG as &$arr) { $file = new SplFileObject($arr); // Truncate file $file->ftruncate(8); // Rewind and reading data from file $file->rewind(); // Print result after truncate echo $file->fgets(); } ?> Output: Geeksfor Contribu Article Reference: http://php.net/manual/en/splfileobject.ftruncate.php Comment More infoAdvertise with us Next Article PHP | SplFileObject ftruncate() Function R R_Raj Follow Improve Article Tags : Web Technologies PHP PHP-function PHP-SplFileInfo 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 ftell() Function The SplFileObject::ftell() function is an inbuilt function of Standard PHP Library (SPL) in PHP which is used to return the position of the file pointer which specifies the current offset in the file. Syntax: int SplFileObject::ftell( void ) Parameters: This function does not accept any parameters. 1 min read PHP | SplFileObject fread() Function The SplFileObject::fread() function is an inbuilt function of Standard PHP Library (SPL) in PHP which is used to reads the given number of bytes from the file. Syntax: string SplFileObject::fread( $length ) Parameters: This function accepts single parameter $length which is used to specify the lengt 1 min read PHP | SplFileObject fgetc() Function The SplFileObject::fgetc() function is an inbuilt function of Standard PHP Library (SPL) in PHP which is used to get character from file. Syntax: string SplFileObject::fgetc( void ) Parameters: This function does not accept any parameter. Return values: Returns single character read from the file or 1 min read PHP SplFileObject fpassthru() Function 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 use 1 min read Like