diff --git a/admin/admin-settings.php b/admin/admin-settings.php index e451b3192b9..c861ffa1529 100644 --- a/admin/admin-settings.php +++ b/admin/admin-settings.php @@ -153,6 +153,14 @@ $woocommerce_settings['general'] = apply_filters('woocommerce_general_settings', 'type' => 'checkbox' ), + array( + 'name' => __('File downloads', 'woothemes'), + 'desc' => __('Use X-Accel-Redirect/ X-Sendfile to serve downloads (server requires mod_xsendfile)', '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' ), diff --git a/readme.txt b/readme.txt index 31eff0eeb26..299e00ccf02 100644 --- a/readme.txt +++ b/readme.txt @@ -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 diff --git a/woocommerce_actions.php b/woocommerce_actions.php index b22e0081518..0457d64bbb2 100644 --- a/woocommerce_actions.php +++ b/woocommerce_actions.php @@ -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. Go to homepage →', 'woothemes'), home_url()) ); - @readfile_chunked("$file_path") or wp_die( sprintf(__('File not found. Go to homepage →', 'woothemes'), home_url()) ); endif;