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