Skip to content
Related Articles

Related Articles

PHP | SplFileInfo openFile() Function

Improve Article
Save Article
  • Last Updated : 18 Dec, 2018
Improve Article
Save Article

The SplFileInfo::openFile() function is an inbuilt function of Standard PHP Library (SPL) in PHP which is used to gets an SplFileObject object for the file.


bool SplFileInfo::openFile( $mode, $path, $context)

Parameters: This function accept three parameters as mention above and describe below.

  • $mode: Specify the mode of opening file.
  • $path: If set it to TRUE, the filename is searched within path.
  • $context: Specifies the manual path for description.

Return values: This function returns opened file as an SplFileObject object.

Note: make sure the file is readable or writable.

Below Program illustrates the SplFileInfo::openFile() function in PHP:


// PHP Program to illustrate 
// Splfileinfo::openFile function
// Make sure file is writable 
$file = new SplFileInfo("gfg.txt");
$obj = $file->openFile('a');
$obj->fwrite("Append...GeeksforGeeks to the file...");

Before Appending the file:

After Appending the file:


My Personal Notes arrow_drop_up
Related Articles

Start Your Coding Journey Now!