Psr17Factory::createStreamFromFile( $filename,  $mode = 'r' )

In this article

Source

public function createStreamFromFile(string $filename, string $mode = 'r'): StreamInterface
{
    if ('' === $filename) {
        throw new \RuntimeException('Path cannot be empty');
    }
    if (\false === $resource = @\fopen($filename, $mode)) {
        if ('' === $mode || \false === \in_array($mode[0], ['r', 'w', 'a', 'x', 'c'], \true)) {
            throw new \InvalidArgumentException(\sprintf('The mode "%s" is invalid.', $mode));
        }
        throw new \RuntimeException(\sprintf('The file "%s" cannot be opened: %s', $filename, \error_get_last()['message'] ?? ''));
    }
    return Stream::create($resource);
}

User Contributed Notes

You must log in before being able to contribute a note or feedback.