Skip to content

Commit

Permalink
Merge pull request #5 from divinity76/patch-1
Browse files Browse the repository at this point in the history
make auto Content-Type optional
  • Loading branch information
songlipeng2003 authored Oct 7, 2022
2 parents 674453c + cfba275 commit b827c6a
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions lib/XSendfile/XSendfile.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public static function detectServer() {
return null;
}

public static function xSendfile( $file, $downFilename = null, $serverType = null, $cache = true ) {
public static function xSendfile( $file, $downFilename = null, $serverType = null, $cache = true, $autoContentType = true ) {
if ( $cache ) {
if ( isset( $_SERVER['HTTP_IF_MODIFIED_SINCE'] ) ) {
$modifiedSince = $_SERVER['HTTP_IF_MODIFIED_SINCE'];
Expand All @@ -47,13 +47,14 @@ public static function xSendfile( $file, $downFilename = null, $serverType = nul
return;
}
}

$finfo = finfo_open( FILEINFO_MIME_TYPE );
$mime = finfo_file( $finfo, $file );
if ( $mime ) {
header( "Content-type: $mime" );
} else {
header( "Content-type: application/octet-stream" );
if( $autoContentType ) {
$finfo = finfo_open( FILEINFO_MIME_TYPE );
$mime = finfo_file( $finfo, $file );
if ( $mime ) {
header( "Content-type: {$mime}" );
} else {
header( "Content-type: application/octet-stream" );
}
}

if ( $downFilename ) {
Expand Down

0 comments on commit b827c6a

Please sign in to comment.