src/FileStreamer.php
/**
     * Send appropriate raw HTTP headers.
     *
     * Remember that headers must be sent before any actual output is sent, either by normal HTML tags, blank lines in
     * a file, or from PHP.
     *
     * @param   int  $type  Type of headers to send.
     *
     * @return void
     */
Send appropriate raw HTTP headers.
Remember that headers must be sent before any actual output is sent, either by normal HTML tags, blank lines in
a file, or from PHP.

@param   int  $type  Type of headers to send.

@return void
Send appropriate raw HTTP headers . Remember that headers must be sent before any actual output is sent either by normal HTML tags blank lines in a file or from PHP . @param int $type Type of headers to send . @return void
private function sendHeaders(int $type): void
    {
        if ($type == self::RANGE_INVALID) {
            header('HTTP/1.1 416 Requested Range Not Satisfiable');
            $this->terminate();
        }
        $filePath = $this->fileInfo->getPathname();
        $fileSize = $this->fileInfo->getSize();
        $fileInfo = new finfo();
        $mimeType = @$fileInfo->file($filePath, FILEINFO_MIME_TYPE);
        header('Pragma: public');
        header('Expires: -1');
        header('Cache-Control: public, must-revalidate, post-check=0, pre-check=0');
        header('Accept-Ranges: bytes');
        $contentType = 'Content-Type: ' . $mimeType ?: 'application/octet-stream';
        header($contentType);
        header('Content-Transfer-Encoding: binary');
        header("Content-Disposition: attachment; filename=\"{$this->fileInfo->getFilename()}\"");
        header("Content-Length: $fileSize");
        switch ($type) {
            case self::CONTENT_INLINE:
                header('Content-Disposition: inline');
                break;
            case self::CONTENT_PARTIAL:
                header('HTTP/1.1 206 Partial Content');
                $rangeCount = count($this->fileRanges);
                if ($rangeCount == 1) {
                    header('Content-Length: ' . ($this->fileRanges[0]['end'] - $this->fileRanges[0]['start'] + 1));
                    header(
                        sprintf(
                            'Content-Range: bytes %d-%d/%d',
                            $this->fileRanges[0]['start'],
                            $this->fileRanges[0]['end'],
                            $fileSize
                        )
                    );
                    return;
                }
                $contentLength = $rangeCount * 38;                                   
                $contentLength += $rangeCount * strlen($contentType . "\r\n");       
                $contentLength += 40;                                                
                foreach ($this->fileRanges as $range) {
                    $contentLength += strlen(
                        sprintf(
                            $this->multipartFormats['rangeFormat'],
                            $range['start'],
                            $range['end'],
                            $fileSize
                        )
                    );
                    $contentLength += $range['end'] - $range['start'] + 1;
                }
                header("Content-Length: $contentLength");
                header('Content-Type: multipart/byteranges; boundary=' . $this->multipartFormats['rangeBoundary']);
        }
    }
private function sendHeaders ( int $ type ) : void { if ( $ type == self :: RANGE_INVALID ) { header ( 'HTTP/1.1 416 Requested Range Not Satisfiable' ) ; $ this -> terminate ( ) ; } $ filePath = $ this -> fileInfo -> getPathname ( ) ; $ fileSize = $ this -> fileInfo -> getSize ( ) ; $ fileInfo = new finfo ( ) ; $ mimeType = @ $ fileInfo -> file ( $ filePath , FILEINFO_MIME_TYPE ) ; header ( 'Pragma: public' ) ; header ( 'Expires: -1' ) ; header ( 'Cache-Control: public, must-revalidate, post-check=0, pre-check=0' ) ; header ( 'Accept-Ranges: bytes' ) ; $ contentType = 'Content-Type: ' . $ mimeType ? : 'application/octet-stream' ; header ( $ contentType ) ; header ( 'Content-Transfer-Encoding: binary' ) ; header ( " Content-Disposition: attachment; filename= \" { $ this -> fileInfo -> getFilename ( ) } \" " ) ; header ( " Content-Length:  $ fileSize " ) ; switch ( $ type ) { case self :: CONTENT_INLINE : header ( 'Content-Disposition: inline' ) ; break ; case self :: CONTENT_PARTIAL : header ( 'HTTP/1.1 206 Partial Content' ) ; $ rangeCount = count ( $ this -> fileRanges ) ; if ( $ rangeCount == 1 ) { header ( 'Content-Length: ' . ( $ this -> fileRanges [ 0 ] [ 'end' ] - $ this -> fileRanges [ 0 ] [ 'start' ] + 1 ) ) ; header ( sprintf ( 'Content-Range: bytes %d-%d/%d' , $ this -> fileRanges [ 0 ] [ 'start' ] , $ this -> fileRanges [ 0 ] [ 'end' ] , $ fileSize ) ) ; return ; } $ contentLength = $ rangeCount * 38 ; $ contentLength += $ rangeCount * strlen ( $ contentType . " \r \n " ) ; $ contentLength += 40 ; foreach ( $ this -> fileRanges as $ range ) { $ contentLength += strlen ( sprintf ( $ this -> multipartFormats [ 'rangeFormat' ] , $ range [ 'start' ] , $ range [ 'end' ] , $ fileSize ) ) ; $ contentLength += $ range [ 'end' ] - $ range [ 'start' ] + 1 ; } header ( " Content-Length:  $ contentLength " ) ; header ( 'Content-Type: multipart/byteranges; boundary=' . $ this -> multipartFormats [ 'rangeBoundary' ] ) ; } }
Send appropriate raw HTTP headers.
Send appropriate raw HTTP headers .
// Get file mimetype. // Caching headers as IE6 workaround. // Range header. // Content headers. // Single range. // Multiple ranges. // boundaryStart // contentType // boundaryEnd // Calculate the content length of the parted download.