diff --git a/inc/media.php b/inc/media.php
index 7e1b2152ddceb1b48afd2bb9f14932e17f4eaa7d..bd80db5778acda2d6722a1dba25c54f91ab46780 100644
--- a/inc/media.php
+++ b/inc/media.php
@@ -237,8 +237,7 @@ function media_upload_xhr($ns,$auth){
     $realSize = stream_copy_to_stream($input, $target);
     fclose($target);
     fclose($input);
-    if ($realSize != (int)$_SERVER["CONTENT_LENGTH"]){
-        unlink($target);
+    if (isset($_SERVER["CONTENT_LENGTH"]) && ($realSize != (int)$_SERVER["CONTENT_LENGTH"])){
         unlink($path);
         return false;
     }