From 2ec295a0cb8ffdfc632d6d74681f0d7cb08d9e8d Mon Sep 17 00:00:00 2001 From: Brent Foosness Date: Thu, 19 Nov 2020 16:16:53 -0500 Subject: [PATCH] Fix required parameter after optional parameter deprecation warning. Fix #21 by defaulting the send method's $contentType to null and setting it to the result of mime_content_type (or application/octet-stream on failure) if a null content type is provided. --- src/File.php | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/File.php b/src/File.php index 98eb3dc..15b1cf2 100644 --- a/src/File.php +++ b/src/File.php @@ -70,8 +70,20 @@ public function __destruct() * @param bool $inline whether to force inline display of the file, even if * filename is present. */ - public function send($filename = null, $contentType, $inline = false) + public function send($filename = null, $contentType = null, $inline = false) { + if (is_null($contentType)) { + $contentType = 'application/octet-stream'; + + if (!is_null($filename)) { + $mimeContentType = mime_content_type($filename); + + if ($mimeContentType !== false) { + $contentType = $mimeContentType; + } + } + } + header('Pragma: public'); header('Expires: 0'); header('Cache-Control: must-revalidate, post-check=0, pre-check=0');