public function sendContentAsFile($content, $attachmentName, $options = [])
    {
        $contentLength = StringHelper::byteLength($content);
        $range = $this->getHttpRange($contentLength);

        if ($range === false) {
            $this->setHeader('Content-Range', "bytes */$contentLength");
            throw new RangeNotSatisfiableHttpException();
        }

        [$begin, $end] = $range;
        $body = new MemoryStream();
        if ($begin != 0 || $end != $contentLength - 1) {
            $this->setStatusCode(206);
            $this->setHeader('Content-Range', "bytes $begin-$end/$contentLength");
            $body->write(StringHelper::byteSubstr($content, $begin, $end - $begin + 1));
        } else {
            $this->setStatusCode(200);
            $body->write($content);
        }

        $mimeType = $options['mimeType'] ?? 'application/octet-stream';
        $this->setDownloadHeaders($attachmentName, $mimeType, !empty($options['inline']), $end - $begin + 1);

        $this->format = self::FORMAT_RAW;
        $this->setBody($body);
        return $this;
    }
public function sendContentAsFile($content, $attachmentName, $options = [])
    {
        $contentLength = StringHelper::byteLength($content);
        $range = $this->getHttpRange($contentLength);

        if ($range === false) {
            $this->setHeader('Content-Range', "bytes */$contentLength");
            throw new RangeNotSatisfiableHttpException();
        }

        [$begin, $end] = $range;
        $body = new MemoryStream();
        if ($begin != 0 || $end != $contentLength - 1) {
            $this->setStatusCode(206);
            $this->setHeader('Content-Range', "bytes $begin-$end/$contentLength");
            $body->write(StringHelper::byteSubstr($content, $begin, $end - $begin + 1));
        } else {
            $this->setStatusCode(200);
            $body->write($content);
        }

        $mimeType = $options['mimeType'] ?? 'application/octet-stream';
        $this->setDownloadHeaders($attachmentName, $mimeType, !empty($options['inline']), $end - $begin + 1);

        $this->format = self::FORMAT_RAW;
        $this->setBody($body);
        return $this;
    }
public function sendContentAsFile ( $ content , $ attachmentName , $ options = [ ] ) { $ contentLength = StringHelper :: byteLength ( $ content ) ; $ range = $ this -> getHttpRange ( $ contentLength ) ; if ( $ range === false ) { $ this -> setHeader ( 'Content-Range' , "bytes */$contentLength" ) ; throw new RangeNotSatisfiableHttpException ( ) ; } [ $ begin , $ end ] = $ range ; $ body = new MemoryStream ( ) ; if ( $ begin != 0 || $ end != $ contentLength - 1 ) { $ this -> setStatusCode ( 206 ) ; $ this -> setHeader ( 'Content-Range' , "bytes $begin-$end/$contentLength" ) ; $ body -> write ( StringHelper :: byteSubstr ( $ content , $ begin , $ end - $ begin + 1 ) ) ; } else { $ this -> setStatusCode ( 200 ) ; $ body -> write ( $ content ) ; } $ mimeType = $ options [ 'mimeType' ] ?? 'application/octet-stream' ; $ this -> setDownloadHeaders ( $ attachmentName , $ mimeType , ! empty ( $ options [ 'inline' ] ) , $ end - $ begin + 1 ) ; $ this -> format = self :: FORMAT_RAW ; $ this -> setBody ( $ body ) ; return $ this ; }
Sends the specified content as a file to the browser.

Note that this method only prepares the response for file sending. The file is not sent
until [[send()]] is called explicitly or implicitly. The latter is done after you return from a controller action.

@param string $content the content to be sent. The existing [[content]] will be discarded.
@param string $attachmentName the file name shown to the user.
@param array $options additional options for sending the file. The following options are supported:

- `mimeType`: the MIME type of the content. Defaults to 'application/octet-stream'.
- `inline`: boolean, whether the browser should open the file within the browser window. Defaults to false,
meaning a download dialog will pop up.

@return $this the response object itself
@throws RangeNotSatisfiableHttpException if the requested range is not satisfiable
@see sendFile() for an example implementation.
Sends the specified content as a file to the browser .