You are here

private function MultipartStream::createElement in Lockr 7.3

Return value

array

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

File

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

Class

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

Namespace

GuzzleHttp\Psr7

Code

private function createElement($name, StreamInterface $stream, $filename, array $headers) {

  // Set a default content-disposition header if one was no provided
  $disposition = $this
    ->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 = $this
    ->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 = $this
    ->getHeader($headers, 'content-type');
  if (!$type && ($filename === '0' || $filename)) {
    if ($type = mimetype_from_filename($filename)) {
      $headers['Content-Type'] = $type;
    }
  }
  return [
    $stream,
    $headers,
  ];
}