diff --git a/file_download.php b/file_download.php index 67bc832a5e..705fc095a0 100644 --- a/file_download.php +++ b/file_download.php @@ -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 );