Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. Filesystem.php

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\Filesystem

Code

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);
    }
}

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal