PHP | SplFileInfo openFile() Function
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.
Syntax:
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:
Program:
<?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..." ); ?> |
Output:
Before Appending the file:
After Appending the file:
Reference: http://php.net/manual/en/splfileinfo.openfile.php
Recommended Posts:
- PHP | SplFileInfo getGroup() Function
- PHP | SplFileInfo getBasename() Function
- PHP | SplFileInfo getFileInfo() Function
- PHP | SplFileInfo getType() Function
- PHP | SplFileInfo getFilename() Function
- PHP | SplFileInfo getSize( ) Function
- PHP | SplFileInfo getPerms() Function
- PHP | SplFileInfo getExtension() Function
- PHP | SplFileInfo getCTime() Function
- PHP | SplFileInfo getRealPath() Function
- PHP | SplFileInfo isLink() Function
- PHP | SplFileInfo getInode() Function
- PHP | SplFileInfo isFile() Function
- PHP | SplFileInfo isReadable() Function
- PHP | SplFileInfo getATime() Function
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.