public function download($target, $alias = null)
    {
        $this->preload($target, $alias);

        // Count file size in bytes
        $size = filesize($target);

        // multipart-download and download resuming support
        if (isset($_SERVER['HTTP_RANGE'])) {

            list($a, $range) = explode("=", $_SERVER['HTTP_RANGE'], 2);
            list($range) = explode(",", $range, 2);
            list($range, $range_end) = explode("-", $range);

            $range = intval($range);

            if (!$range_end) {
                $range_end = $size - 1;
            } else {
                $range_end = intval($range_end);
            }

            $new_length = $range_end - $range + 1;

            $headers = array(
                'Content-Length' => $new_length,
                'Content-Range' => sprintf('bytes %s', $range - $range_end / $size)
            );

            $this->headerBag->setStatusCode(206)
                            ->setPairs($headers)
                            ->send();
        } else {

            $new_length = $size;
            $this->headerBag->appendPair('Content-Length', $size)
                            ->send()
                            ->clear();
        }

        $chunksize = 1024 * 1024;
        $bytes_send = 0;

        $target = fopen($target, 'r');

        if (isset($_SERVER['HTTP_RANGE'])) {
            fseek($target, $range);
        }

        while (!feof($target) && (!connection_aborted()) && ($bytes_send < $new_length)) {

            $buffer = fread($target, $chunksize);
            print($buffer);
            flush();
            $bytes_send += strlen($buffer);
        }

        fclose($target);
    }
public function download($target, $alias = null)
    {
        $this->preload($target, $alias);

        // Count file size in bytes
        $size = filesize($target);

        // multipart-download and download resuming support
        if (isset($_SERVER['HTTP_RANGE'])) {

            list($a, $range) = explode("=", $_SERVER['HTTP_RANGE'], 2);
            list($range) = explode(",", $range, 2);
            list($range, $range_end) = explode("-", $range);

            $range = intval($range);

            if (!$range_end) {
                $range_end = $size - 1;
            } else {
                $range_end = intval($range_end);
            }

            $new_length = $range_end - $range + 1;

            $headers = array(
                'Content-Length' => $new_length,
                'Content-Range' => sprintf('bytes %s', $range - $range_end / $size)
            );

            $this->headerBag->setStatusCode(206)
                            ->setPairs($headers)
                            ->send();
        } else {

            $new_length = $size;
            $this->headerBag->appendPair('Content-Length', $size)
                            ->send()
                            ->clear();
        }

        $chunksize = 1024 * 1024;
        $bytes_send = 0;

        $target = fopen($target, 'r');

        if (isset($_SERVER['HTTP_RANGE'])) {
            fseek($target, $range);
        }

        while (!feof($target) && (!connection_aborted()) && ($bytes_send < $new_length)) {

            $buffer = fread($target, $chunksize);
            print($buffer);
            flush();
            $bytes_send += strlen($buffer);
        }

        fclose($target);
    }
public function download ( $ target , $ alias = null ) { $ this -> preload ( $ target , $ alias ) ; // Count file size in bytes $ size = filesize ( $ target ) ; // multipart-download and download resuming support if ( isset ( $ _SERVER [ 'HTTP_RANGE' ] ) ) { list ( $ a , $ range ) = explode ( "=" , $ _SERVER [ 'HTTP_RANGE' ] , 2 ) ; list ( $ range ) = explode ( "," , $ range , 2 ) ; list ( $ range , $ range_end ) = explode ( "-" , $ range ) ; $ range = intval ( $ range ) ; if ( ! $ range_end ) { $ range_end = $ size - 1 ; } else { $ range_end = intval ( $ range_end ) ; } $ new_length = $ range_end - $ range + 1 ; $ headers = array ( 'Content-Length' => $ new_length , 'Content-Range' => sprintf ( 'bytes %s' , $ range - $ range_end / $ size ) ) ; $ this -> headerBag -> setStatusCode ( 206 ) -> setPairs ( $ headers ) -> send ( ) ; } else { $ new_length = $ size ; $ this -> headerBag -> appendPair ( 'Content-Length' , $ size ) -> send ( ) -> clear ( ) ; } $ chunksize = 1024 * 1024 ; $ bytes_send = 0 ; $ target = fopen ( $ target , 'r' ) ; if ( isset ( $ _SERVER [ 'HTTP_RANGE' ] ) ) { fseek ( $ target , $ range ) ; } while ( ! feof ( $ target ) && ( ! connection_aborted ( ) ) && ( $ bytes_send < $ new_length ) ) { $ buffer = fread ( $ target , $ chunksize ) ; print ( $ buffer ) ; flush ( ) ; $ bytes_send += strlen ( $ buffer ) ; } fclose ( $ target ) ; }
Sends downloadable headers for a file

@param string $filename A path to the target file
@param string $alias Basename name can be optionally changed
@throws \RuntimeException If can't access the target file
@return void
Sends downloadable headers for a file