public function setDownloadHeaders($attachmentName, $mimeType = null, $inline = false, $contentLength = null)
    {
        $disposition = $inline ? 'inline' : 'attachment';

        $headers = [
            'Pragma' => 'public',
            'Accept-Ranges' => 'bytes',
            'Expires' => '0',
            'Cache-Control' => 'must-revalidate, post-check=0, pre-check=0',
            'Content-Disposition' => $this->getDispositionHeaderValue($disposition, $attachmentName),
        ];

        if ($mimeType !== null) {
            $headers['Content-Type'] = $mimeType;
        }

        if ($contentLength !== null) {
            $headers['Content-Length'] = $contentLength;
        }

        foreach ($headers as $name => $value) {
            if (!$this->hasHeader($name)) {
                $this->setHeader($name, $value);
            }
        }

        return $this;
    }
public function setDownloadHeaders($attachmentName, $mimeType = null, $inline = false, $contentLength = null)
    {
        $disposition = $inline ? 'inline' : 'attachment';

        $headers = [
            'Pragma' => 'public',
            'Accept-Ranges' => 'bytes',
            'Expires' => '0',
            'Cache-Control' => 'must-revalidate, post-check=0, pre-check=0',
            'Content-Disposition' => $this->getDispositionHeaderValue($disposition, $attachmentName),
        ];

        if ($mimeType !== null) {
            $headers['Content-Type'] = $mimeType;
        }

        if ($contentLength !== null) {
            $headers['Content-Length'] = $contentLength;
        }

        foreach ($headers as $name => $value) {
            if (!$this->hasHeader($name)) {
                $this->setHeader($name, $value);
            }
        }

        return $this;
    }
public function setDownloadHeaders ( $ attachmentName , $ mimeType = null , $ inline = false , $ contentLength = null ) { $ disposition = $ inline ? 'inline' : 'attachment' ; $ headers = [ 'Pragma' => 'public' , 'Accept-Ranges' => 'bytes' , 'Expires' => '0' , 'Cache-Control' => 'must-revalidate, post-check=0, pre-check=0' , 'Content-Disposition' => $ this -> getDispositionHeaderValue ( $ disposition , $ attachmentName ) , ] ; if ( $ mimeType !== null ) { $ headers [ 'Content-Type' ] = $ mimeType ; } if ( $ contentLength !== null ) { $ headers [ 'Content-Length' ] = $ contentLength ; } foreach ( $ headers as $ name => $ value ) { if ( ! $ this -> hasHeader ( $ name ) ) { $ this -> setHeader ( $ name , $ value ) ; } } return $ this ; }
Sets a default set of HTTP headers for file downloading purpose.
@param string $attachmentName the attachment file name
@param string $mimeType the MIME type for the response. If null, `Content-Type` header will NOT be set.
@param bool $inline whether the browser should open the file within the browser window. Defaults to false,
meaning a download dialog will pop up.
@param int $contentLength the byte length of the file being downloaded. If null, `Content-Length` header will NOT be set.
@return $this the response object itself
Sets a default set of HTTP headers for file downloading purpose .