mod_xsendfile

This commit is contained in:
Mike Jolley 2011-11-07 21:52:04 +00:00
parent 7d980111de
commit 89a289b0c4
3 changed files with 20 additions and 13 deletions

View File

@ -153,6 +153,14 @@ $woocommerce_settings['general'] = apply_filters('woocommerce_general_settings',
'type' => 'checkbox'
),
array(
'name' => __('File downloads', 'woothemes'),
'desc' => __('Use <code>X-Accel-Redirect</code>/ <code>X-Sendfile</code> to serve downloads (server requires <code>mod_xsendfile</code>)', 'woothemes'),
'id' => 'woocommerce_mod_xsendfile_enabled',
'type' => 'checkbox',
'std' => 'no',
),
array( 'type' => 'sectionend', 'id' => 'general_options'),
array( 'name' => __( 'ShareThis', 'woothemes' ), 'type' => 'title', 'desc' => '', 'id' => 'share_this' ),

View File

@ -99,6 +99,7 @@ Yes you can! Join in on our GitHub repository :) https://github.com/woothemes/wo
* add_to_cart shortcode
* Improved order search
* Option to unforce SSL checkout
* Support for X-Accel-Redirect / X-Sendfile for downloads
= 1.2 - 03/11/2011 =
* Added quick status change buttons (processing/complete) to orders panel

View File

@ -759,14 +759,22 @@ function woocommerce_download_product() {
case "jpe": case "jpeg": case "jpg": $ctype="image/jpg"; break;
default: $ctype="application/force-download";
endswitch;
if (get_option('woocommerce_mod_xsendfile_enabled')=='yes') :
header("X-Accel-Redirect: $file_path");
header("X-Sendfile: $file_path");
header("Content-Type: $ctype");
header("Content-Disposition: attachment; filename=\"".basename($file_path)."\";");
exit;
// Headers
endif;
@session_write_close();
if (function_exists('apache_setenv')) @apache_setenv('no-gzip', 1);
@ini_set('zlib.output_compression', 'Off');
@set_time_limit(0);
@set_magic_quotes_runtime(0);
@ob_end_clean();
if (ob_get_level()) @ob_end_clean(); // Zip corruption fix
@ -776,15 +784,7 @@ function woocommerce_download_product() {
header("Robots: none");
header("Content-Type: ".$ctype."");
header("Content-Description: File Transfer");
if (strstr($_SERVER['HTTP_USER_AGENT'], "MSIE")) {
// workaround for IE filename bug with multiple periods / multiple dots in filename
$iefilename = preg_replace('/\./', '%2e', basename($file_path), substr_count(basename($file_path), '.') - 1);
header("Content-Disposition: attachment; filename=\"".$iefilename."\";");
} else {
header("Content-Disposition: attachment; filename=\"".basename($file_path)."\";");
}
header("Content-Disposition: attachment; filename=\"".basename($file_path)."\";");
header("Content-Transfer-Encoding: binary");
if ($size = @filesize($file_path)) header("Content-Length: ".$size);
@ -796,8 +796,6 @@ function woocommerce_download_product() {
else :
if (!file_exists($file_path)) wp_die( sprintf(__('File not found. <a href="%s">Go to homepage &rarr;</a>', 'woothemes'), home_url()) );
@readfile_chunked("$file_path") or wp_die( sprintf(__('File not found. <a href="%s">Go to homepage &rarr;</a>', 'woothemes'), home_url()) );
endif;