From 8158333d936c333abefff772d03c20cf9f67ae54 Mon Sep 17 00:00:00 2001 From: schmigz <75388888+schmigz@users.noreply.github.com> Date: Sat, 5 Jun 2021 02:27:53 -0400 Subject: [PATCH] Update tinyfilemanager.php (#568) fm_get_file_mimes() was causing errors for unknown extensions as it was causing an error as array element was not defined and return value was never checked. According to https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/MIME_types/Common_types and several other resources, application/octet-stream is the default value for all other cases. An unknown file type should use this type. I put a check in there to use that by default so a valid value is always returned. It might be useful to replace this function with the built-in PHP function mime_content_type() but that adds some additional dependencies as it does not always work out of the box with PHP. --- tinyfilemanager.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tinyfilemanager.php b/tinyfilemanager.php index bb35f1c..d0fe6db 100644 --- a/tinyfilemanager.php +++ b/tinyfilemanager.php @@ -2945,6 +2945,10 @@ function fm_get_file_mimes($extension) $fileTypes['php'] = ['application/x-php']; $fileTypes['html'] = ['text/html']; $fileTypes['txt'] = ['text/plain']; + //Unknown mime-types should be 'application/octet-stream' + if(empty($fileTypes[$extension])) { + $fileTypes[$extension] = ['application/octet-stream']; + } return $fileTypes[$extension]; }