file_get_contents

Supported Versions: PHP 4 >= 4.3.0, PHP 5, PHP 7, PHP 8
Reads entire file into a string
<?php file_get_contents(    string $filename,    bool $use_include_path = false,    ?resource $context = null,    int $offset = 0,    ?int $length = null): string|false
<?php     public function fetching_the_mime_type_of_an_svg_file(): void

    {

        $this->runScenario(function () {

            $this->givenWeHaveAnExistingFile('file.svg', file_get_contents(__DIR__ . '/test_files/flysystem.svg'));



            $mimetype = $this->adapter()->mimeType('file.svg')->mimeType();
<?php     {

        $this->givenWeHaveAnExistingFile(

            'unknown-mime-type.md5',

            file_get_contents(__DIR__ . '/test_files/unknown-mime-type.md5')

        );



        $this->expectException(UnableToRetrieveMetadata::class);
<?php         $adapter = $this->adapter();

        $adapter->write(

            self::PATH,

            (string) file_get_contents(__DIR__ . '/../AdapterTestUtilities/test_files/flysystem.svg'),

            new Config()

        );
<?php     {

        $location = $this->prefixer->prefixPath($path);

        error_clear_last();

        $contents = @file_get_contents($location);



        if ($contents === false) {

            throw UnableToReadFile::fromLocation($path, error_get_last()['message'] ?? '');
<?php         $adapter->write('/file.txt', 'contents', new Config());



        $this->assertFileExists(static::ROOT . '/file.txt');

        $contents = file_get_contents(static::ROOT . '/file.txt');

        $this->assertEquals('contents', $contents);

    }
<?php         fclose($stream);



        $this->assertFileExists(static::ROOT . '/file.txt');

        $contents = file_get_contents(static::ROOT . '/file.txt');

        $this->assertEquals('contents', $contents);

    }
<?php         $adapter = new LocalFilesystemAdapter(static::ROOT);

        $adapter->write(

            'flysystem.svg',

            (string) file_get_contents(__DIR__ . '/../AdapterTestUtilities/test_files/flysystem.svg'),

            new Config()

        );

        $this->assertStringStartsWith('image/svg', $adapter->mimeType('flysystem.svg')->mimeType());
<?php     private function assertFileContains(string $file, string $expectedContents): void

    {

        $this->assertFileExists($file);

        $contents = file_get_contents($file);

        $this->assertEquals($expectedContents, $contents);

    }
<?php     public function detecting_mimetype(): void

    {

        $adapter = $this->adapter();

        $adapter->write('file.svg', (string) file_get_contents(__DIR__ . '/../AdapterTestUtilities/test_files/flysystem.svg'), new Config());



        $mimeType = $adapter->mimeType('file.svg');
<?php     private function loadPrivateKey(): RSA

    {

        if ("---" !== substr($this->privateKey, 0, 3) && is_file($this->privateKey)) {

            $this->privateKey = file_get_contents($this->privateKey);

        }



        $key = new RSA();
<?php     public function verifying_a_fingerprint(): void

    {

        $key = file_get_contents(__DIR__ . '/../../test_files/sftp/ssh_host_rsa_key.pub');

        $fingerPrint = $this->computeFingerPrint($key);



        $provider = SftpConnectionProvider::fromArray(
<?php     public function detecting_mimetype(): void

    {

        $adapter = $this->adapter();

        $adapter->write('file.svg', (string) file_get_contents(__DIR__ . '/../AdapterTestUtilities/test_files/flysystem.svg'), new Config());



        $mimeType = $adapter->mimeType('file.svg');
<?php     private function loadPrivateKey(): AsymmetricKey

    {

        if ("---" !== substr($this->privateKey, 0, 3) && is_file($this->privateKey)) {

            $this->privateKey = file_get_contents($this->privateKey);

        }



        try {
<?php     public function verifying_a_fingerprint(): void

    {

        $key = file_get_contents(__DIR__ . '/../../test_files/sftp/ssh_host_ed25519_key.pub');

        $fingerPrint = $this->computeFingerPrint($key);



        $provider = SftpConnectionProvider::fromArray(