Skip to content

Commit fbac390

Browse files
committedDec 6, 2011
Allow content types to be overriden when downloading files
Fixes #13439: Wrong Content-type for various MSOffice documents
1 parent bfc04a4 commit fbac390

File tree

3 files changed

+42
-0
lines changed

3 files changed

+42
-0
lines changed
 

‎config_defaults_inc.php

+16
Original file line numberDiff line numberDiff line change
@@ -3486,6 +3486,22 @@
34863486
'zip' => 'zip.gif',
34873487
'?' => 'generic.gif' );
34883488

3489+
/**
3490+
*
3491+
* Content types which will be overriden when downloading files
3492+
*
3493+
* @global array $g_file_download_content_type_overrides
3494+
*/
3495+
$g_file_download_content_type_overrides = array (
3496+
'docx' => 'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
3497+
'dotx' => 'application/vnd.openxmlformats-officedocument.wordprocessingml.template',
3498+
'pptx' => 'application/vnd.openxmlformats-officedocument.presentationml.presentation',
3499+
'ppsx' => 'application/vnd.openxmlformats-officedocument.presentationml.slideshow',
3500+
'potx' => 'application/vnd.openxmlformats-officedocument.presentationml.template',
3501+
'xlsx' => 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
3502+
'xltx' => 'application/vnd.openxmlformats-officedocument.spreadsheetml.template'
3503+
);
3504+
34893505
/**
34903506
* Icon associative arrays
34913507
* Status to icon mapping

‎core/file_api.php

+15
Original file line numberDiff line numberDiff line change
@@ -1063,3 +1063,18 @@ function file_copy_attachments( $p_source_bug_id, $p_dest_bug_id ) {
10631063
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'] ) );
10641064
}
10651065
}
1066+
1067+
/**
1068+
* Returns a possibly override content type for a file name
1069+
*
1070+
* @param string $p_filename the filename of the file which will be downloaded
1071+
* @return string the content type, or empty if it should not be overriden
1072+
*/
1073+
function file_get_content_type_override( $p_filename ) {
1074+
1075+
global $g_file_download_content_type_overrides;
1076+
1077+
$t_extension = pathinfo( $p_filename, PATHINFO_EXTENSION );
1078+
1079+
return $g_file_download_content_type_overrides[$t_extension];
1080+
}

‎file_download.php

+11
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,8 @@
167167

168168
$t_content_type = $v_file_type;
169169

170+
$t_content_type_override = file_get_content_type_override ( $t_filename );
171+
170172
# dump file content to the connection.
171173
switch ( config_get( 'file_upload_method' ) ) {
172174
case DISK:
@@ -180,6 +182,9 @@
180182
$t_content_type = $t_file_info_type;
181183
}
182184
}
185+
186+
if ( $t_content_type_override )
187+
$t_content_type = $t_content_type_override;
183188

184189
header( 'Content-Type: ' . $t_content_type );
185190
if ( config_get( 'file_download_xsendfile_enabled' ) ) {
@@ -206,6 +211,9 @@
206211
$t_content_type = $t_file_info_type;
207212
}
208213
}
214+
215+
if ( $t_content_type_override )
216+
$t_content_type = $t_content_type_override;
209217

210218
header( 'Content-Type: ' . $t_content_type );
211219
readfile( $t_local_disk_file );
@@ -218,6 +226,9 @@
218226
$t_content_type = $t_file_info_type;
219227
}
220228
}
229+
230+
if ( $t_content_type_override )
231+
$t_content_type = $t_content_type_override;
221232

222233
header( 'Content-Type: ' . $t_content_type );
223234
echo $v_content;

0 commit comments

Comments
 (0)