fopen

Supported Versions: PHP 4, PHP 5, PHP 7, PHP 8
Opens file or URL
<?php fopen(    string $filename,    string $mode,    bool $use_include_path = false,    ?resource $context = null): resource|false
<?php     {

        $contents = '';



        $handle = fopen($path, 'rb');



        if ($handle) {

            try {
<?php             [$path, $file, $name, $options] = ['', $path, $file, $name ?? []];

        }



        $stream = fopen(is_string($file) ? $file : $file->getRealPath(), 'r');
<?php     protected function createResource($path, $mode)

    {

        $this->handle = fopen($path, $mode);

    }
<?php         file_put_contents($this->tempDir.'/foo.txt', 'some-data');



        $filesystemAdapter = new FilesystemAdapter($this->filesystem, $this->adapter);

        $stream = fopen($this->tempDir.'/foo.txt', 'r');

        $guzzleStream = new Stream($stream);

        $filesystemAdapter->put('bar.txt', $guzzleStream);

        fclose($stream);
<?php         $this->assertFalse($disk->deleteDirectory('directory'));

        $this->assertFalse($disk->prepend('path.txt', 'data'));

        $this->assertFalse($disk->append('path.txt', 'data'));

        $handle = fopen('php://memory', 'rw');

        fwrite($handle, 'content');

        $this->assertFalse($disk->writeStream('path.txt', $handle));

        fclose($handle);
<?php     public function testSendStreamRequestBody()

    {

        $string = 'Look at me, i am a stream!!';

        $resource = fopen('php://temp', 'w');

        fwrite($resource, $string);

        rewind($resource);

        $body = Utils::streamFor($resource);
<?php     {

        $this->factory->fakeSequence()->push('abc123');



        $resource = fopen('php://temp', 'w');



        $this->factory->sink($resource)->get('https://example.com');
<?php             'foo.com/*' => ['page' => 'foo'],

        ]);



        $resource = fopen('php://temp', 'w');



        $this->factory->sink($resource)->get('http://foo.com/test');
<?php     {

        $response = TestResponse::fromBaseResponse(

            new StreamedResponse(function () {

                $stream = fopen('php://memory', 'r+');

                fwrite($stream, 'expected response data');

                rewind($stream);

                fpassthru($stream);
<?php     }



    assert(isset($getopt['status-file']) && is_string($getopt['status-file']));

    $statusFile = fopen($getopt['status-file'], 'wb');

    assert(is_resource($statusFile));



    assert(isset($getopt['progress-file']) && is_string($getopt['progress-file']));
<?php             return;

        }



        $teamcityLogFileHandle = fopen($this->options->configuration->logfileTeamcity(), 'ab+');

        assert($teamcityLogFileHandle !== false);

        $this->teamcityLogFileHandle = $teamcityLogFileHandle;

    }
<?php     {

        $path = $file->getPathname();

        assert($path !== '');

        $handle = fopen($path, 'r');

        assert($handle !== false);

        $fseek = fseek($handle, $this->tailPositions[$path] ?? 0);

        assert($fseek === 0);
<?php         }



        if (is_string($value)) {

            $fp = fopen('php://temp', 'rb+');

            assert(is_resource($fp));

            fwrite($fp, $value);

            fseek($fp, 0);
<?php         }



        if (is_string($value)) {

            $fp = fopen('php://temp', 'rb+');

            assert(is_resource($fp));

            fwrite($fp, $value);

            fseek($fp, 0);
<?php         $this->connection->insert('blob_table', [

            'id'        => 1,

            'clobcolumn' => 'ignored',

            'blobcolumn' => fopen('data://text/plain,' . $longBlob, 'r'),

        ], [

            ParameterType::INTEGER,

            ParameterType::STRING,