Skip to content
Snippets Groups Projects
Commit 0d7f9fb2 authored by ale's avatar ale
Browse files

Autodetect MIME type if missing

parent 9a3707c1
No related branches found
No related tags found
No related merge requests found
Pipeline #54083 passed
......@@ -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']);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment