Skip to content

Commit

Permalink
Show images inline instead of downloading them
Browse files Browse the repository at this point in the history
Fixes #22543
  • Loading branch information
vboctor committed Mar 29, 2017
1 parent 5898638 commit 741acf2
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions file_download.php
Expand Up @@ -190,13 +190,24 @@
$t_content_type = $t_content_type_override;
}

# Don't allow inline flash
if( false !== strpos( $t_content_type, 'application/x-shockwave-flash' ) ) {
http_content_disposition_header( $t_filename );
} else {
http_content_disposition_header( $t_filename, $f_show_inline );
# Decide what should open inline in the browser vs. download as attachment
# https://www.thoughtco.com/mime-types-by-content-type-3469108
$t_show_inline = $f_show_inline;
$t_mime_force_inline = array(
'image/jpeg', 'image/gif', 'image/tiff', 'image/bmp', 'image/svg+xml', 'image/png',
);
$t_mime_force_attachment = array( 'application/x-shockwave-flash' );

$t_mime_type = substr( $t_content_type, 0, strpos( $t_content_type, ';' ) );

if( in_array( $t_mime_type, $t_mime_force_inline ) ) {
$t_show_inline = true;
} else if( in_array( $t_mime_type, $t_mime_force_attachment ) ) {
$t_show_inline = false;
}

http_content_disposition_header( $t_filename, $t_show_inline );

header( 'Content-Type: ' . $t_content_type );
header( 'Content-Length: ' . $v_filesize );

Expand Down

0 comments on commit 741acf2

Please sign in to comment.