|
11 | 11 | */
|
12 | 12 | class File
|
13 | 13 | {
|
| 14 | + const DEFAULT_CONTENT_TYPE = 'application/octet-stream'; |
| 15 | + |
14 | 16 | /**
|
15 | 17 | * @var bool whether to delete the tmp file when it's no longer referenced
|
16 | 18 | * or when the request ends. Default is `true`.
|
@@ -66,16 +68,24 @@ public function __destruct()
|
66 | 68 | *
|
67 | 69 | * @param string|null $filename the filename to send. If empty, the file is
|
68 | 70 | * 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. |
70 | 74 | * @param bool $inline whether to force inline display of the file, even if
|
71 | 75 | * filename is present.
|
72 | 76 | */
|
73 |
| - public function send($filename = null, $contentType, $inline = false) |
| 77 | + public function send($filename = null, $contentType = null, $inline = false) |
74 | 78 | {
|
| 79 | + if ($contentType === null) { |
| 80 | + $contentType = @mime_content_type($this->_filename); |
| 81 | + if ($contentType === false) { |
| 82 | + $contentType = self::DEFAULT_CONTENT_TYPE; |
| 83 | + } |
| 84 | + } |
75 | 85 | header('Pragma: public');
|
76 | 86 | header('Expires: 0');
|
77 | 87 | header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
|
78 |
| - header('Content-Type: '.$contentType); |
| 88 | + header('Content-Type: ' . $contentType); |
79 | 89 | header('Content-Transfer-Encoding: binary');
|
80 | 90 |
|
81 | 91 | //#11 Undefined index: HTTP_USER_AGENT
|
|
0 commit comments