WooCommerce Code Reference

WC_Download_Handler
in package

Download handler class.

Table of Contents

count_download()  : mixed
Count download.
download()  : mixed
Download a file - hook into init function.
download_file_force()  : mixed
Force download - this is the default method.
download_file_redirect()  : mixed
Redirect to a file to start the download.
download_file_xsendfile()  : mixed
Download a file using X-Sendfile, X-Lighttpd-Sendfile, or X-Accel-Redirect if available.
download_product()  : mixed
Check if we need to download a file and check validity.
ie_nocache_headers_fix()  : array<string|int, mixed>
Filter headers for IE to fix issues over SSL.
init()  : mixed
Hook in methods.
parse_file_path()  : array<string|int, mixed>
Parse file path and see if its remote or local.
readfile_chunked()  : bool
Read file chunked.
get_download_range()  : array<string|int, mixed>
Parse the HTTP_RANGE request from iOS devices.
check_download_expiry()  : mixed
Check if the download has expired.
check_download_login_required()  : mixed
Check if a download requires the user to login first.
check_downloads_remaining()  : mixed
Check if there are downloads remaining.
check_order_is_valid()  : mixed
Check if an order is valid for downloading from.
check_server_config()  : mixed
Check and set certain server config variables to ensure downloads work as intended.
clean_buffers()  : mixed
Clean all output buffers.
download_error()  : mixed
Die with an error message if the download fails.
download_headers()  : mixed
Set headers for the download.
get_content_disposition()  : string
Get selected content disposition
get_download_content_type()  : string
Get content type of a download.

Methods

count_download()

Count download.

public static count_download(array<string|int, mixed> $download_data) : mixed
Parameters
$download_data : array<string|int, mixed>

Download data.

Tags
deprecated
4.4.0
Return values
mixed

download()

Download a file - hook into init function.

public static download(string $file_path, int $product_id) : mixed
Parameters
$file_path : string

URL to file.

$product_id : int

Product ID of the product being downloaded.

Return values
mixed

download_file_force()

Force download - this is the default method.

public static download_file_force(string $file_path, string $filename) : mixed
Parameters
$file_path : string

File path.

$filename : string

File name.

Return values
mixed

download_file_redirect()

Redirect to a file to start the download.

public static download_file_redirect(string $file_path[, string $filename = '' ]) : mixed
Parameters
$file_path : string

File path.

$filename : string = ''

File name.

Return values
mixed

download_file_xsendfile()

Download a file using X-Sendfile, X-Lighttpd-Sendfile, or X-Accel-Redirect if available.

public static download_file_xsendfile(string $file_path, string $filename) : mixed
Parameters
$file_path : string

File path.

$filename : string

File name.

Return values
mixed

ie_nocache_headers_fix()

Filter headers for IE to fix issues over SSL.

public static ie_nocache_headers_fix(array<string|int, mixed> $headers) : array<string|int, mixed>

IE bug prevents download via SSL when Cache Control and Pragma no-cache headers set.

Parameters
$headers : array<string|int, mixed>

HTTP headers.

Return values
array<string|int, mixed>

parse_file_path()

Parse file path and see if its remote or local.

public static parse_file_path(string $file_path) : array<string|int, mixed>
Parameters
$file_path : string

File path.

Return values
array<string|int, mixed>

readfile_chunked()

Read file chunked.

public static readfile_chunked(string $file, int $start, int $length) : bool

Reads file in chunks so big downloads are possible without changing PHP.INI - http://codeigniter.com/wiki/Download_helper_for_large_files/.

Parameters
$file : string

File.

$start : int

Byte offset/position of the beginning from which to read from the file.

$length : int

Length of the chunk to be read from the file in bytes, 0 means full file.

Return values
boolSuccess or fail

get_download_range()

Parse the HTTP_RANGE request from iOS devices.

protected static get_download_range(int $file_size) : array<string|int, mixed>

Does not support multi-range requests.

Parameters
$file_size : int

Size of file in bytes.

Return values
array<string|int, mixed>{ Information about range download request: beginning and length of file chunk, whether the range is valid/supported and whether the request is a range request. @type int $start Byte offset of the beginning of the range. Default 0. @type int $length Length of the requested file chunk in bytes. Optional. @type bool $is_range_valid Whether the requested range is a valid and supported range. @type bool $is_range_request Whether the request is a range request. }

check_server_config()

Check and set certain server config variables to ensure downloads work as intended.

private static check_server_config() : mixed
Return values
mixed

clean_buffers()

Clean all output buffers.

private static clean_buffers() : mixed

Can prevent errors, for example: transfer closed with 3 bytes remaining to read.

Return values
mixed

download_error()

Die with an error message if the download fails.

private static download_error(string $message[, string $title = '' ][, int $status = 404 ]) : mixed
Parameters
$message : string

Error message.

$title : string = ''

Error title.

$status : int = 404

Error status.

Return values
mixed

download_headers()

Set headers for the download.

private static download_headers(string $file_path, string $filename[, array<string|int, mixed> $download_range = array() ]) : mixed
Parameters
$file_path : string

File path.

$filename : string

File name.

$download_range : array<string|int, mixed> = array()

Array containing info about range download request (see {@see} for structure).

Return values
mixed

get_content_disposition()

Get selected content disposition

private static get_content_disposition() : string

Defaults to attachment if woocommerce_downloads_deliver_inline setting is not selected.

Return values
stringContent disposition value.

get_download_content_type()

Get content type of a download.

private static get_download_content_type(string $file_path) : string
Parameters
$file_path : string

File path.

Return values
string