diff --git a/config_defaults_inc.php b/config_defaults_inc.php index ef5cd8c2c7..a894e3b658 100644 --- a/config_defaults_inc.php +++ b/config_defaults_inc.php @@ -3486,6 +3486,22 @@ 'zip' => 'zip.gif', '?' => 'generic.gif' ); +/** + * + * Content types which will be overriden when downloading files + * + * @global array $g_file_download_content_type_overrides + */ +$g_file_download_content_type_overrides = array ( + 'docx' => 'application/vnd.openxmlformats-officedocument.wordprocessingml.document', + 'dotx' => 'application/vnd.openxmlformats-officedocument.wordprocessingml.template', + 'pptx' => 'application/vnd.openxmlformats-officedocument.presentationml.presentation', + 'ppsx' => 'application/vnd.openxmlformats-officedocument.presentationml.slideshow', + 'potx' => 'application/vnd.openxmlformats-officedocument.presentationml.template', + 'xlsx' => 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', + 'xltx' => 'application/vnd.openxmlformats-officedocument.spreadsheetml.template' +); + /** * Icon associative arrays * Status to icon mapping diff --git a/core/file_api.php b/core/file_api.php index 51e0e69d88..fc44dd7d11 100644 --- a/core/file_api.php +++ b/core/file_api.php @@ -1063,3 +1063,18 @@ function file_copy_attachments( $p_source_bug_id, $p_dest_bug_id ) { db_query_bound( $query, Array( $p_dest_bug_id, $t_bug_file['title'], $t_bug_file['description'], $t_new_diskfile_name, $t_new_file_name, $t_bug_file['folder'], $t_bug_file['filesize'], $t_bug_file['file_type'], $t_bug_file['date_added'], $t_bug_file['content'] ) ); } } + +/** + * Returns a possibly override content type for a file name + * + * @param string $p_filename the filename of the file which will be downloaded + * @return string the content type, or empty if it should not be overriden + */ +function file_get_content_type_override( $p_filename ) { + + global $g_file_download_content_type_overrides; + + $t_extension = pathinfo( $p_filename, PATHINFO_EXTENSION ); + + return $g_file_download_content_type_overrides[$t_extension]; +} \ No newline at end of file diff --git a/file_download.php b/file_download.php index b72cedce97..f59ae4ce52 100644 --- a/file_download.php +++ b/file_download.php @@ -167,6 +167,8 @@ $t_content_type = $v_file_type; +$t_content_type_override = file_get_content_type_override ( $t_filename ); + # dump file content to the connection. switch ( config_get( 'file_upload_method' ) ) { case DISK: @@ -180,6 +182,9 @@ $t_content_type = $t_file_info_type; } } + + if ( $t_content_type_override ) + $t_content_type = $t_content_type_override; header( 'Content-Type: ' . $t_content_type ); if ( config_get( 'file_download_xsendfile_enabled' ) ) { @@ -206,6 +211,9 @@ $t_content_type = $t_file_info_type; } } + + if ( $t_content_type_override ) + $t_content_type = $t_content_type_override; header( 'Content-Type: ' . $t_content_type ); readfile( $t_local_disk_file ); @@ -218,6 +226,9 @@ $t_content_type = $t_file_info_type; } } + + if ( $t_content_type_override ) + $t_content_type = $t_content_type_override; header( 'Content-Type: ' . $t_content_type ); echo $v_content;