Filter the filename Closes #5074

This commit is contained in:
Mike Jolley 2014-03-14 10:04:41 +00:00
parent e23ad23503
commit ccddd1df05
1 changed files with 7 additions and 5 deletions

View File

@ -245,16 +245,18 @@ class WC_Download_Handler {
nocache_headers(); nocache_headers();
} }
$file_name = basename( $file_path ); $filename = basename( $file_path );
if ( strstr( $file_name, '?' ) ) { if ( strstr( $filename, '?' ) ) {
$file_name = current( explode( '?', $file_name ) ); $filename = current( explode( '?', $filename ) );
} }
$filename = apply_filters( 'woocommerce_file_download_filename', $filename, $product_id );
header( "X-Robots-Tag: noindex, nofollow", true ); header( "X-Robots-Tag: noindex, nofollow", true );
header( "Content-Type: " . $ctype ); header( "Content-Type: " . $ctype );
header( "Content-Description: File Transfer" ); header( "Content-Description: File Transfer" );
header( "Content-Disposition: attachment; filename=\"" . $file_name . "\";" ); header( "Content-Disposition: attachment; filename=\"" . $filename . "\";" );
header( "Content-Transfer-Encoding: binary" ); header( "Content-Transfer-Encoding: binary" );
if ( $size = @filesize( $file_path ) ) { if ( $size = @filesize( $file_path ) ) {
@ -268,7 +270,7 @@ class WC_Download_Handler {
$file_path = trim( preg_replace( '`^' . str_replace( '\\', '/', getcwd() ) . '`' , '', $file_path ), '/' ); $file_path = trim( preg_replace( '`^' . str_replace( '\\', '/', getcwd() ) . '`' , '', $file_path ), '/' );
} }
header( "Content-Disposition: attachment; filename=\"" . $file_name . "\";" ); header( "Content-Disposition: attachment; filename=\"" . $filename . "\";" );
if ( function_exists( 'apache_get_modules' ) && in_array( 'mod_xsendfile', apache_get_modules() ) ) { if ( function_exists( 'apache_get_modules' ) && in_array( 'mod_xsendfile', apache_get_modules() ) ) {