public static function sendAttachment($source, ResponseInterface $response = null, $options = [])
    {
        $stream = $source;

        if (!$stream instanceof StreamInterface) {
            $stream = new Stream($stream, 'r');
        }

        /** @var ResponseInterface $response */
        $response = $response ?: new Response();

        $filename = null;

        if (is_string($source)) {
            $filename = pathinfo($source, PATHINFO_BASENAME);
        }

        if (isset($options['filename'])) {
            $filename = $options['filename'];
        }

        $response = HeaderHelper::prepareAttachmentHeaders($response, $filename);

        $response = $response->withBody($stream);

        $output = static::$outputObject;

        if (!$output instanceof StreamOutput) {
            $output = new StreamOutput();
        }

        if (isset($options['delay'])) {
            $output->setDelay($options['delay']);
        }

        $output->respond($response);
    }
public static function sendAttachment($source, ResponseInterface $response = null, $options = [])
    {
        $stream = $source;

        if (!$stream instanceof StreamInterface) {
            $stream = new Stream($stream, 'r');
        }

        /** @var ResponseInterface $response */
        $response = $response ?: new Response();

        $filename = null;

        if (is_string($source)) {
            $filename = pathinfo($source, PATHINFO_BASENAME);
        }

        if (isset($options['filename'])) {
            $filename = $options['filename'];
        }

        $response = HeaderHelper::prepareAttachmentHeaders($response, $filename);

        $response = $response->withBody($stream);

        $output = static::$outputObject;

        if (!$output instanceof StreamOutput) {
            $output = new StreamOutput();
        }

        if (isset($options['delay'])) {
            $output->setDelay($options['delay']);
        }

        $output->respond($response);
    }
public static function sendAttachment ( $ source , ResponseInterface $ response = null , $ options = [ ] ) { $ stream = $ source ; if ( ! $ stream instanceof StreamInterface ) { $ stream = new Stream ( $ stream , 'r' ) ; } /** @var ResponseInterface $response */ $ response = $ response ? : new Response ( ) ; $ filename = null ; if ( is_string ( $ source ) ) { $ filename = pathinfo ( $ source , PATHINFO_BASENAME ) ; } if ( isset ( $ options [ 'filename' ] ) ) { $ filename = $ options [ 'filename' ] ; } $ response = HeaderHelper :: prepareAttachmentHeaders ( $ response , $ filename ) ; $ response = $ response -> withBody ( $ stream ) ; $ output = static :: $ outputObject ; if ( ! $ output instanceof StreamOutput ) { $ output = new StreamOutput ( ) ; } if ( isset ( $ options [ 'delay' ] ) ) { $ output -> setDelay ( $ options [ 'delay' ] ) ; } $ output -> respond ( $ response ) ; }
A simple method to quickly send attachment stream download.

@param   string|resource|StreamInterface $source    The file source, can be file path or resource.
@param   ResponseInterface               $response  A custom Response object to contain your headers.
@param   array                           $options   Options to provide some settings, currently supports
"delay" and "filename".

@return  void
A simple method to quickly send attachment stream download .