diff --git a/wp-mat.php b/wp-mat.php
index 694f051fb6c97b0971607abbefbf196c882f7b61..9c7700a9df5da749628988299fd823add670522e 100644
--- a/wp-mat.php
+++ b/wp-mat.php
@@ -3,7 +3,7 @@
  * Plugin Name: wp-mat
  * Plugin URI: https://git.autistici.org/noblogs/wp-mat
  * Description: Process uploaded files through MAT
- * Version: 0.0.8
+ * Version: 0.0.9
  * Author: Autistici/Inventati
  * Author URI: https://www.autistici.org/
  * License: MIT
@@ -73,11 +73,15 @@ function wp_mat_handle_upload_prefilter($file) {
     // file with the sanitized one.
     $new_tmp_file = tempnam("", "wp_mat_");
     if (wp_mat_issue_request($file['tmp_name'], $file['type'], $new_tmp_file)) {
+        // Rename the cleaned up file to the original file, or WP
+        // will not pass the is_uploaded_file() check in wp_handle_upload().
         unlink($file['tmp_name']);
+        rename($new_tmp_file, $file['tmp_name']);
+
         $new_file = array(
             "name" => $file['name'],
             "type" => $file['type'],
-            "tmp_name" => $new_tmp_file,
+            "tmp_name" => $file['tmp_name'],
             "size" => filesize($new_tmp_file),
             "error" => 0,
         );