function Filesystem::appendToFile
Appends content to an existing file.
Parameters
string|resource $content The content to append:
bool $lock Whether the file should be locked when writing to it:
Throws
IOException If the file is not writable
File
-
vendor/
symfony/ filesystem/ Filesystem.php, line 695
Class
- Filesystem
- Provides basic utility to manipulate the file system.
Namespace
Symfony\Component\FilesystemCode
public function appendToFile(string $filename, $content, bool $lock = false) : void {
if (\is_array($content)) {
throw new \TypeError(\sprintf('Argument 2 passed to "%s()" must be string or resource, array given.', __METHOD__));
}
$dir = \dirname($filename);
if (!is_dir($dir)) {
$this->mkdir($dir);
}
if (false === self::box('file_put_contents', $filename, $content, \FILE_APPEND | ($lock ? \LOCK_EX : 0))) {
throw new IOException(\sprintf('Failed to write file "%s": ', $filename) . self::$lastError, 0, null, $filename);
}
}