public function attachment(
        $filename,
        string $name = '',
        string $mime = 'application/octet-stream'
    ): ResponseInterface {
        if (empty($name)) {
            if (!is_string($filename)) {
                throw new ResponseException("Unable to resolve public filename");
            }

            $name = basename($filename);
        }

        $stream = $this->getStream($filename);

        $response = $this->responseFactory->createResponse();
        $response = $response->withHeader('Content-Type', $mime);
        $response = $response->withHeader('Content-Length', (string)$stream->getSize());
        $response = $response->withHeader(
            'Content-Disposition',
            'attachment; filename="' . addcslashes($name, '"') . '"'
        );

        return $response->withBody($stream);
    }
public function attachment(
        $filename,
        string $name = '',
        string $mime = 'application/octet-stream'
    ): ResponseInterface {
        if (empty($name)) {
            if (!is_string($filename)) {
                throw new ResponseException("Unable to resolve public filename");
            }

            $name = basename($filename);
        }

        $stream = $this->getStream($filename);

        $response = $this->responseFactory->createResponse();
        $response = $response->withHeader('Content-Type', $mime);
        $response = $response->withHeader('Content-Length', (string)$stream->getSize());
        $response = $response->withHeader(
            'Content-Disposition',
            'attachment; filename="' . addcslashes($name, '"') . '"'
        );

        return $response->withBody($stream);
    }
public function attachment ( $ filename , string $ name = '' , string $ mime = 'application/octet-stream' ) : ResponseInterface { if ( empty ( $ name ) ) { if ( ! is_string ( $ filename ) ) { throw new ResponseException ( "Unable to resolve public filename" ) ; } $ name = basename ( $ filename ) ; } $ stream = $ this -> getStream ( $ filename ) ; $ response = $ this -> responseFactory -> createResponse ( ) ; $ response = $ response -> withHeader ( 'Content-Type' , $ mime ) ; $ response = $ response -> withHeader ( 'Content-Length' , ( string ) $ stream -> getSize ( ) ) ; $ response = $ response -> withHeader ( 'Content-Disposition' , 'attachment; filename="' . addcslashes ( $ name , '"' ) . '"' ) ; return $ response -> withBody ( $ stream ) ; }
Configure response to send given attachment to client.

@param string|StreamInterface|StreamableInterface $filename Local filename or stream or streamable or resource.
@param string                                     $name     Public file name (in attachment), by default local
filename. Name is mandratory when filename supplied
in a form of stream or resource.
@param string                                     $mime

@return ResponseInterface

@throws ResponseException
Configure response to send given attachment to client .