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

Breadcrumb

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

function MultipartStream::createElement

Parameters

string[] $headers:

Return value

array{0: StreamInterface, 1: string[]}

1 call to MultipartStream::createElement()
MultipartStream::addElement in vendor/guzzlehttp/psr7/src/MultipartStream.php

File

vendor/guzzlehttp/psr7/src/MultipartStream.php, line 120

Class

MultipartStream
Stream that when read returns bytes for a streaming multipart or multipart/form-data stream.

Namespace

GuzzleHttp\Psr7

Code

private function createElement(string $name, StreamInterface $stream, ?string $filename, array $headers) : array {
    // Set a default content-disposition header if one was no provided
    $disposition = self::getHeader($headers, 'content-disposition');
    if (!$disposition) {
        $headers['Content-Disposition'] = $filename === '0' || $filename ? sprintf('form-data; name="%s"; filename="%s"', $name, basename($filename)) : "form-data; name=\"{$name}\"";
    }
    // Set a default content-length header if one was no provided
    $length = self::getHeader($headers, 'content-length');
    if (!$length) {
        if ($length = $stream->getSize()) {
            $headers['Content-Length'] = (string) $length;
        }
    }
    // Set a default Content-Type if one was not supplied
    $type = self::getHeader($headers, 'content-type');
    if (!$type && ($filename === '0' || $filename)) {
        $headers['Content-Type'] = MimeType::fromFilename($filename) ?? 'application/octet-stream';
    }
    return [
        $stream,
        $headers,
    ];
}

API Navigation

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