diff --git a/wp-mat.php b/wp-mat.php index 8a03014667ae07524ef1c1875c59ed44ba1d5ecc..4b9d8bdd0aa14e72adf887724f43c4e24ad1176e 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']);