From 0d7f9fb20fc558b29ad2b5dcc4a2fe2a246cd71e Mon Sep 17 00:00:00 2001
From: ale <ale@incal.net>
Date: Fri, 2 Jun 2023 09:37:55 +0100
Subject: [PATCH] Autodetect MIME type if missing

---
 wp-mat.php | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/wp-mat.php b/wp-mat.php
index 8a03014..4b9d8bd 100644
--- a/wp-mat.php
+++ b/wp-mat.php
@@ -54,11 +54,20 @@ function wp_mat_handle_upload_prefilter($file) {
     if (isset($file['error'])) {
         return $file;
     }
+
+    // Autodetect MIME type if not passed by the browser.
+    if (!$file['type']) {
+        $file['type'] = mime_content_type($file['tmp_name']);
+    }
+
+    // Check if it's one of the MIME types we support.
     if (!wp_mat_is_supported_mime_type($file['type'])) {
         error_log("wp-mat: unsupported mime type ".$file['type']);
         return $file;
     }
 
+    // Issue a request to the MAT API, and if successful replace the
+    // file with the sanitized one.
     $new_tmp_file = tempnam("", "wp_mat_");
     if (wp_mat_issue_request($file['tmp_name'], $file['type'], $new_tmp_file)) {
         unlink($file['tmp_name']);
-- 
GitLab