diff --git a/mongoose.c b/mongoose.c
index 1293836b490c70bc1baedbd07c7a03fb27a67034..762b9091a7b7fdaa4225b2ca6c4b7c634f6c387f 100644
--- a/mongoose.c
+++ b/mongoose.c
@@ -4227,8 +4227,11 @@ int mg_upload(struct mg_connection *conn, const char *destination_dir) {
     fp = NULL;
     // Construct destination file name. Do not allow paths to have slashes.
     if ((s = strrchr(fname, '/')) == NULL) {
-      s = fname;
+        if ((s = strrchr(fname, '\\')) == NULL) {
+            s = fname;
+        }
     }
+    
     // Open file in binary mode. TODO: set an exclusive lock.
     snprintf(path, sizeof(path), "%s/%s", destination_dir, s);
     if ((fp = fopen(path, "wb")) == NULL) {