SplFileInfo::openFile
(PHP 5 >= 5.1.2, PHP 7)
SplFileInfo::openFile — Gets an SplFileObject object for the file
Description
$open_mode
= "r"
[, bool $use_include_path
= FALSE
[, resource $context
= NULL
]]] ) : SplFileObjectCreates an SplFileObject object of the file. This is useful because SplFileObject contains additional methods for manipulating the file whereas SplFileInfo is only useful for gaining information, like whether the file is writable.
Parameters
-
open_mode
-
The mode for opening the file. See the fopen() documentation for descriptions of possible modes. The default is read only.
-
use_include_path
-
When set to
TRUE
, the filename is also searched for within the include_path -
context
-
Refer to the context section of the manual for a description of contexts.
Errors/Exceptions
A RuntimeException if the file cannot be opened (e.g. insufficient access rights).
Examples
Example #1 SplFileInfo::openFile() example
<?php
$fileinfo = new SplFileInfo('/tmp/foo.txt');
if ($fileinfo->isWritable()) {
$fileobj = $fileinfo->openFile('a');
$fileobj->fwrite("appended this sample text");
}
?>
See Also
- SplFileObject
- stream_context_create() - Creates a stream context
- fopen() - Opens file or URL
English translation
You have asked to visit this site in English. For now, only the interface is translated, but not all the content yet.If you want to help me in translations, your contribution is welcome. All you need to do is register on the site, and send me a message asking me to add you to the group of translators, which will give you the opportunity to translate the pages you want. A link at the bottom of each translated page indicates that you are the translator, and has a link to your profile.
Thank you in advance.
Document created the 30/01/2003, last modified the 26/10/2018
Source of the printed document:https://www.gaudry.be/en/php-rf-splfileinfo.openfile.html
The infobrol is a personal site whose content is my sole responsibility. The text is available under CreativeCommons license (BY-NC-SA). More info on the terms of use and the author.
References
These references and links indicate documents consulted during the writing of this page, or which may provide additional information, but the authors of these sources can not be held responsible for the content of this page.
The author This site is solely responsible for the way in which the various concepts, and the freedoms that are taken with the reference works, are presented here. Remember that you must cross multiple source information to reduce the risk of errors.