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.
This commit is contained in:
schmigz 2021-06-05 02:27:53 -04:00 committed by GitHub
parent e843adcf0b
commit 8158333d93
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 4 additions and 0 deletions

View File

@ -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];
}