WC_Download_Handler::download_file_xsendfile() public WC 1.0
Download a file using X-Sendfile, X-Lighttpd-Sendfile, or X-Accel-Redirect if available.
{} Это метод класса: WC_Download_Handler{}
Хуки из метода
Возвращает
Null. Ничего.
Использование
$result = WC_Download_Handler::download_file_xsendfile( $file_path, $filename );
- $file_path(строка) (обязательный)
- File path.
- $filename(строка) (обязательный)
- File name.
Код WC_Download_Handler::download_file_xsendfile() WC Download Handler::download file xsendfile WC 5.0.0
public static function download_file_xsendfile( $file_path, $filename ) {
$parsed_file_path = self::parse_file_path( $file_path );
/**
* Fallback on force download method for remote files. This is because:
* 1. xsendfile needs proxy configuration to work for remote files, which cannot be assumed to be available on most hosts.
* 2. Force download method is more secure than redirect method if `allow_url_fopen` is enabled in `php.ini`. We fallback to redirect method in force download method anyway in case `allow_url_fopen` is not enabled.
*/
if ( $parsed_file_path['remote_file'] && ! apply_filters( 'woocommerce_use_xsendfile_for_remote', false ) ) {
do_action( 'woocommerce_download_file_force', $file_path, $filename );
return;
}
if ( function_exists( 'apache_get_modules' ) && in_array( 'mod_xsendfile', apache_get_modules(), true ) ) {
self::download_headers( $parsed_file_path['file_path'], $filename );
$filepath = apply_filters( 'woocommerce_download_file_xsendfile_file_path', $parsed_file_path['file_path'], $file_path, $filename, $parsed_file_path );
header( 'X-Sendfile: ' . $filepath );
exit;
} elseif ( stristr( getenv( 'SERVER_SOFTWARE' ), 'lighttpd' ) ) {
self::download_headers( $parsed_file_path['file_path'], $filename );
$filepath = apply_filters( 'woocommerce_download_file_xsendfile_lighttpd_file_path', $parsed_file_path['file_path'], $file_path, $filename, $parsed_file_path );
header( 'X-Lighttpd-Sendfile: ' . $filepath );
exit;
} elseif ( stristr( getenv( 'SERVER_SOFTWARE' ), 'nginx' ) || stristr( getenv( 'SERVER_SOFTWARE' ), 'cherokee' ) ) {
self::download_headers( $parsed_file_path['file_path'], $filename );
$xsendfile_path = trim( preg_replace( '`^' . str_replace( '\\', '/', getcwd() ) . '`', '', $parsed_file_path['file_path'] ), '/' );
$xsendfile_path = apply_filters( 'woocommerce_download_file_xsendfile_x_accel_redirect_file_path', $xsendfile_path, $file_path, $filename, $parsed_file_path );
header( "X-Accel-Redirect: /$xsendfile_path" );
exit;
}
// Fallback.
self::download_file_force( $file_path, $filename );
}