makeFile.php
Table of Contents
Functions
- makeFile() : string
- Creates or updates a file with the given content and options.
Functions
makeFile()
Creates or updates a file with the given content and options.
makeFile(array{append?: bool, content?: string|null, file?: string|null, force?: bool, group?: null|string, lock?: bool, overwrite?: bool, permissions?: int, owner?: string|null}|string|null $fileOrOptions[, string|null $content = null ][, array{append?: bool, force?: bool, group?: null|string, lock?: bool, overwrite?: bool, permissions?: int, owner?: string|null} $options = [] ]) : string
This function writes content to the specified file path. It supports appending to existing files, overwriting, setting file permissions, changing ownership, and group. It can also create the parent directories if needed.
Usage:
- Classic signature:
makeFile(string $filePath, string $content = '', array $options = []);
- Signature with options array as first parameter:
makeFile(array $options);
Required keys in $options:
- 'filePath' (string): The path of the file to create or modify (mandatory).
- 'content' (string): The content to write into the file (optional, default ''). Other keys correspond to options (see below).
Parameters
- $fileOrOptions : array{append?: bool, content?: string|null, file?: string|null, force?: bool, group?: null|string, lock?: bool, overwrite?: bool, permissions?: int, owner?: string|null}|string|null
-
Either the file path as a string (classic usage), or an associative array containing at least 'filePath' and optionally 'content' and other options.
- $content : string|null = null
-
The content to write into the file. Defaults to empty string. Ignored if $filePathOrOptions is array.
- $options : array{append?: bool, force?: bool, group?: null|string, lock?: bool, overwrite?: bool, permissions?: int, owner?: string|null} = []
-
An associative array of options:
- 'append' (bool): If true, appends content instead of overwriting. Default: false.
- 'force' (bool): If true, creates parent directories if they do not exist. Default: true.
- 'group' (string|null): Group name or ID to set as file group owner. Default: null.
- 'lock' (bool): If true, uses an exclusive lock while writing. Default: true.
- 'overwrite' (bool): If true, overwrites existing files. Default: false.
- 'permissions' (int): File permissions to set (octal). Default: 0644.
- 'owner' (string|null): User name or ID to set as file owner. Default: null.
Tags
Return values
string —The path of the created or updated file.