Skip to content

Commit f162f70

Browse files
authored
Merge pull request #24 from mikehaertl/21-fix-deprecation-warning
Issue #21 Fix deprecation warning in PHP8
2 parents 20a1879 + 1da599f commit f162f70

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

src/File.php

+13-3
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
*/
1212
class File
1313
{
14+
const DEFAULT_CONTENT_TYPE = 'application/octet-stream';
15+
1416
/**
1517
* @var bool whether to delete the tmp file when it's no longer referenced
1618
* or when the request ends. Default is `true`.
@@ -66,16 +68,24 @@ public function __destruct()
6668
*
6769
* @param string|null $filename the filename to send. If empty, the file is
6870
* streamed inline.
69-
* @param string $contentType the Content-Type header
71+
* @param string|null $contentType the Content-Type header to send. If
72+
* `null` the type is auto-detected and if that fails
73+
* 'application/octet-stream' is used.
7074
* @param bool $inline whether to force inline display of the file, even if
7175
* filename is present.
7276
*/
73-
public function send($filename = null, $contentType, $inline = false)
77+
public function send($filename = null, $contentType = null, $inline = false)
7478
{
79+
if ($contentType === null) {
80+
$contentType = @mime_content_type($this->_filename);
81+
if ($contentType === false) {
82+
$contentType = self::DEFAULT_CONTENT_TYPE;
83+
}
84+
}
7585
header('Pragma: public');
7686
header('Expires: 0');
7787
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
78-
header('Content-Type: '.$contentType);
88+
header('Content-Type: ' . $contentType);
7989
header('Content-Transfer-Encoding: binary');
8090

8191
//#11 Undefined index: HTTP_USER_AGENT

0 commit comments

Comments
 (0)