Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit d6b9592

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 ce3a276 commit d6b9592

File tree

3 files changed

+45
-0
lines changed

3 files changed

+45
-0
lines changed
 

‎config_defaults_inc.php

+16
Original file line numberDiff line numberDiff line change
@@ -3256,6 +3256,22 @@
32563256
'zip' => 'zip.gif',
32573257
'?' => 'generic.gif' );
32583258

3259+
/**
3260+
*
3261+
* Content types which will be overriden when downloading files
3262+
*
3263+
* @global array $g_file_download_content_type_overrides
3264+
*/
3265+
$g_file_download_content_type_overrides = array (
3266+
'docx' => 'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
3267+
'dotx' => 'application/vnd.openxmlformats-officedocument.wordprocessingml.template',
3268+
'pptx' => 'application/vnd.openxmlformats-officedocument.presentationml.presentation',
3269+
'ppsx' => 'application/vnd.openxmlformats-officedocument.presentationml.slideshow',
3270+
'potx' => 'application/vnd.openxmlformats-officedocument.presentationml.template',
3271+
'xlsx' => 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
3272+
'xltx' => 'application/vnd.openxmlformats-officedocument.spreadsheetml.template'
3273+
);
3274+
32593275
/**
32603276
* Icon associative arrays
32613277
* Status to icon mapping

‎core/file_api.php

+15
Original file line numberDiff line numberDiff line change
@@ -893,3 +893,18 @@ function file_copy_attachments( $p_source_bug_id, $p_dest_bug_id ) {
893893
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'] ) );
894894
}
895895
}
896+
897+
/**
898+
* Returns a possibly override content type for a file name
899+
*
900+
* @param string $p_filename the filename of the file which will be downloaded
901+
* @return string the content type, or empty if it should not be overriden
902+
*/
903+
function file_get_content_type_override( $p_filename ) {
904+
905+
global $g_file_download_content_type_overrides;
906+
907+
$t_extension = pathinfo( $p_filename, PATHINFO_EXTENSION );
908+
909+
return $g_file_download_content_type_overrides[$t_extension];
910+
}

‎file_download.php

+14
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,8 @@
143143
$finfo = finfo_get_if_available();
144144

145145
$t_content_type = $v_file_type;
146+
147+
$t_content_type_override = file_get_content_type_override ( $t_filename );
146148

147149
# dump file content to the connection.
148150
switch ( config_get( 'file_upload_method' ) ) {
@@ -157,6 +159,10 @@
157159
$t_content_type = $t_file_info_type;
158160
}
159161
}
162+
163+
if ( $t_content_type_override ) {
164+
$t_content_type = $t_content_type_override;
165+
}
160166

161167
header( 'Content-Type: ' . $t_content_type );
162168
readfile( $t_local_disk_file );
@@ -178,6 +184,10 @@
178184
$t_content_type = $t_file_info_type;
179185
}
180186
}
187+
188+
if ( $t_content_type_override ) {
189+
$t_content_type = $t_content_type_override;
190+
}
181191

182192
header( 'Content-Type: ' . $t_content_type );
183193
readfile( $t_local_disk_file );
@@ -190,6 +200,10 @@
190200
$t_content_type = $t_file_info_type;
191201
}
192202
}
203+
204+
if ( $t_content_type_override ) {
205+
$t_content_type = $t_content_type_override;
206+
}
193207

194208
header( 'Content-Type: ' . $t_content_type );
195209
echo $v_content;

0 commit comments

Comments
 (0)
Please sign in to comment.