public function addResource($name, $resource, array $options = [])
    {
        $stream = $this->streamFactory->createStream($resource);

        // validate options['headers'] exists
        if (!isset($options['headers'])) {
            $options['headers'] = [];
        }

        // Try to add filename if it is missing
        if (empty($options['filename'])) {
            $options['filename'] = null;
            $uri = $stream->getMetadata('uri');
            if ('php://' !== substr($uri, 0, 6)) {
                $options['filename'] = $uri;
            }
        }

        $this->prepareHeaders($name, $stream, $options['filename'], $options['headers']);
        $this->data[] = ['contents' => $stream, 'headers' => $options['headers'], 'filename' => $options['filename']];

        return $this;
    }
public function addResource($name, $resource, array $options = [])
    {
        $stream = $this->streamFactory->createStream($resource);

        // validate options['headers'] exists
        if (!isset($options['headers'])) {
            $options['headers'] = [];
        }

        // Try to add filename if it is missing
        if (empty($options['filename'])) {
            $options['filename'] = null;
            $uri = $stream->getMetadata('uri');
            if ('php://' !== substr($uri, 0, 6)) {
                $options['filename'] = $uri;
            }
        }

        $this->prepareHeaders($name, $stream, $options['filename'], $options['headers']);
        $this->data[] = ['contents' => $stream, 'headers' => $options['headers'], 'filename' => $options['filename']];

        return $this;
    }
public function addResource ( $ name , $ resource , array $ options = [ ] ) { $ stream = $ this -> streamFactory -> createStream ( $ resource ) ; // validate options['headers'] exists if ( ! isset ( $ options [ 'headers' ] ) ) { $ options [ 'headers' ] = [ ] ; } // Try to add filename if it is missing if ( empty ( $ options [ 'filename' ] ) ) { $ options [ 'filename' ] = null ; $ uri = $ stream -> getMetadata ( 'uri' ) ; if ( 'php://' !== substr ( $ uri , 0 , 6 ) ) { $ options [ 'filename' ] = $ uri ; } } $ this -> prepareHeaders ( $ name , $ stream , $ options [ 'filename' ] , $ options [ 'headers' ] ) ; $ this -> data [ ] = [ 'contents' => $ stream , 'headers' => $ options [ 'headers' ] , 'filename' => $ options [ 'filename' ] ] ; return $ this ; }
Add a resource to the Multipart Stream.

@param string                          $name     the formpost name
@param string|resource|StreamInterface $resource
@param array                           $options  {

@var array $headers additional headers ['header-name' => 'header-value']
@var string $filename
}

@return MultipartStreamBuilder
Add a resource to the Multipart Stream .