public static function StreamOrDownloadFileFromPath(
        string $filePath,
        string $name = null,
        bool $deleteOnCompleted = true,
        bool $inlineDisposition = true,
        bool $knownSize = true
    ): BinaryFileResponse
    {
        $name = $name ?: static::getFileBaseName($filePath);
        $stream = ($knownSize === true ? $filePath : new Stream($filePath));
        $response = new BinaryFileResponse($stream);

        $response->headers->set(
            'Content-Type',
            static::getMimeType(pathinfo($name, PATHINFO_EXTENSION))
        );
        $response->setContentDisposition(
            (
            $inlineDisposition === true
                ?
                ResponseHeaderBag::DISPOSITION_INLINE
                :
                ResponseHeaderBag::DISPOSITION_ATTACHMENT
            ),
            $name
        );

        if ($deleteOnCompleted === true) {
            $response->deleteFileAfterSend(true);
        }
        // $response->send();

        return $response;
    }
public static function StreamOrDownloadFileFromPath(
        string $filePath,
        string $name = null,
        bool $deleteOnCompleted = true,
        bool $inlineDisposition = true,
        bool $knownSize = true
    ): BinaryFileResponse
    {
        $name = $name ?: static::getFileBaseName($filePath);
        $stream = ($knownSize === true ? $filePath : new Stream($filePath));
        $response = new BinaryFileResponse($stream);

        $response->headers->set(
            'Content-Type',
            static::getMimeType(pathinfo($name, PATHINFO_EXTENSION))
        );
        $response->setContentDisposition(
            (
            $inlineDisposition === true
                ?
                ResponseHeaderBag::DISPOSITION_INLINE
                :
                ResponseHeaderBag::DISPOSITION_ATTACHMENT
            ),
            $name
        );

        if ($deleteOnCompleted === true) {
            $response->deleteFileAfterSend(true);
        }
        // $response->send();

        return $response;
    }
public static function StreamOrDownloadFileFromPath ( string $ filePath , string $ name = null , bool $ deleteOnCompleted = true , bool $ inlineDisposition = true , bool $ knownSize = true ) : BinaryFileResponse { $ name = $ name ? : static :: getFileBaseName ( $ filePath ) ; $ stream = ( $ knownSize === true ? $ filePath : new Stream ( $ filePath ) ) ; $ response = new BinaryFileResponse ( $ stream ) ; $ response -> headers -> set ( 'Content-Type' , static :: getMimeType ( pathinfo ( $ name , PATHINFO_EXTENSION ) ) ) ; $ response -> setContentDisposition ( ( $ inlineDisposition === true ? ResponseHeaderBag :: DISPOSITION_INLINE : ResponseHeaderBag :: DISPOSITION_ATTACHMENT ) , $ name ) ; if ( $ deleteOnCompleted === true ) { $ response -> deleteFileAfterSend ( true ) ; } // $response->send();
 return $ response ; }
This will send the file while the browser decides if to open or output for download.

@param string $filePath
@param string|null $name
@param bool $deleteOnCompleted
@param bool $inlineDisposition
@param bool $knownSize
@return BinaryFileResponse
@throws \Throwable
This will send the file while the browser decides if to open or output for download .