bp_media_download_headers( string $file_path, string $filename, array $download_range = array() )

Set headers for the download.

Description

Parameters

$file_path

(Required) File path.

$filename

(Required) File name.

$download_range

(Optional) Array containing info about range download request (see get_download_range for structure).

Default value: array()

Source

File: bp-media/bp-media-filters.php

1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
function bp_media_download_headers( $file_path, $filename, $download_range = array() ) {
    bp_media_check_server_config();
    bp_media_clean_buffers();
    bp_media_nocache_headers();
 
    header( 'X-Robots-Tag: noindex, nofollow', true );
    header( 'Content-Type: ' . bp_media_get_download_content_type( $file_path ) );
    header( 'Content-Description: File Transfer' );
    header( 'Content-Disposition: attachment; filename="' . $filename . '";' );
    header( 'Content-Transfer-Encoding: binary' );
 
    $file_size = @filesize( $file_path ); // phpcs:ignore Generic.PHP.NoSilencedErrors.Discouraged
    if ( ! $file_size ) {
        return;
    }
 
    if ( isset( $download_range['is_range_request'] ) && true === $download_range['is_range_request'] ) {
        if ( false === $download_range['is_range_valid'] ) {
            header( 'HTTP/1.1 416 Requested Range Not Satisfiable' );
            header( 'Content-Range: bytes 0-' . ( $file_size - 1 ) . '/' . $file_size );
            exit;
        }
 
        $start  = $download_range['start'];
        $end    = $download_range['start'] + $download_range['length'] - 1;
        $length = $download_range['length'];
 
        header( 'HTTP/1.1 206 Partial Content' );
        header( "Accept-Ranges: 0-$file_size" );
        header( "Content-Range: bytes $start-$end/$file_size" );
        header( "Content-Length: $length" );
    } else {
        header( 'Content-Length: ' . $file_size );
    }
}

Changelog

Changelog
Version Description
BuddyBoss 1.4.1 Introduced.

Questions?

We're always happy to help with code or other questions you might have! Search our developer docs, contact support, or connect with our sales team.