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

Breadcrumb

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

function Filesystem::readFile

Returns the content of a file as a string.

Throws

IOException If the file cannot be read

File

vendor/symfony/filesystem/Filesystem.php, line 717

Class

Filesystem
Provides basic utility to manipulate the file system.

Namespace

Symfony\Component\Filesystem

Code

public function readFile(string $filename) : string {
    if (is_dir($filename)) {
        throw new IOException(\sprintf('Failed to read file "%s": File is a directory.', $filename));
    }
    $content = self::box('file_get_contents', $filename);
    if (false === $content) {
        throw new IOException(\sprintf('Failed to read file "%s": ', $filename) . self::$lastError, 0, null, $filename);
    }
    return $content;
}

API Navigation

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