WC_Download_Handler::download_headers
Set headers for the download.
Метод класса: WC_Download_Handler{}
Хуков нет.
Возвращает
null. Ничего (null).
Использование
$result = WC_Download_Handler::download_headers( $file_path, $filename, $download_range, $remote_file );
- $file_path(строка) (обязательный)
- File path.
- $filename(строка) (обязательный)
- File name.
- $download_range(массив)
- Array containing info about range download request (see {@see get_download_range} for structure).
По умолчанию:array() - $remote_file(true|false)
- Whether the download is a remote file.
По умолчанию:false
Код WC_Download_Handler::download_headers() WC Download Handler::download headers WC 11.3.0
private static function download_headers( $file_path, $filename, $download_range = array(), $remote_file = false ) {
self::check_server_config();
self::clean_buffers();
wc_nocache_headers();
$content_type = self::get_content_type_for_served_download( $file_path, $filename, $remote_file );
header( 'X-Robots-Tag: noindex, nofollow', true );
header( 'Content-Type: ' . $content_type );
header( 'Content-Description: File Transfer' );
header( 'Content-Disposition: ' . self::get_content_disposition() . '; 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'] ) {
status_header( 416 );
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'];
status_header( 206 );
header( "Accept-Ranges: 0-$file_size" );
header( "Content-Range: bytes $start-$end/$file_size" );
header( "Content-Length: $length" );
} else {
header( 'Content-Length: ' . $file_size );
}
}