@@ -52,6 +52,7 @@ trait ResponseDownload
5252 * @param int $delay Delay between flushs in microseconds
5353 * @param int $readLength Bytes read by flush
5454 * @param string|null $filename A custom filename
55+ * @param string|null $contentType A custom Content-Type
5556 *
5657 * @throws InvalidArgumentException If invalid file path
5758 * @throws RuntimeException If can not get the file size or modification time
@@ -64,7 +65,8 @@ public function setDownload(
6465 bool $ acceptRanges = true ,
6566 int $ delay = 0 ,
6667 int $ readLength = 1024 ,
67- ?string $ filename = null
68+ ?string $ filename = null ,
69+ ?string $ contentType = null
6870 ) : static {
6971 $ realpath = \realpath ($ filepath );
7072 if ($ realpath === false || !\is_file ($ realpath )) {
@@ -106,10 +108,10 @@ public function setDownload(
106108 }
107109 }
108110 $ this ->setHeader (ResponseHeader::CONTENT_LENGTH , (string ) $ this ->filesize );
109- $ this -> setHeader (
110- ResponseHeader:: CONTENT_TYPE ,
111- \mime_content_type ( $ this -> filepath ) ?: ' application/octet-stream '
112- );
111+ if ( $ contentType === null ) {
112+ $ contentType = \mime_content_type ( $ this -> filepath ) ?: ' application/octet-stream ' ;
113+ }
114+ $ this -> setHeader (ResponseHeader:: CONTENT_TYPE , $ contentType );
113115 $ this ->sendType = 'normal ' ;
114116 return $ this ;
115117 }
0 commit comments