Просмотр исходного кода

Fix multiple file upload (issue #55)

bel 10 лет назад
Родитель
Сommit
a5eadbca86
2 измененных файлов с 11 добавлено и 2 удалено
  1. 1 0
      examples/upload/upload.c
  2. 10 2
      src/civetweb.c

+ 1 - 0
examples/upload/upload.c

@@ -36,6 +36,7 @@ static int begin_request_handler(struct mg_connection *conn)
             "<form method=\"POST\" action=\"/handle_post_request\" "
             "  enctype=\"multipart/form-data\">"
             "<input type=\"file\" name=\"file\" /> <br/>"
+            "<input type=\"file\" name=\"file2\" /> <br/>"
             "<input type=\"submit\" value=\"Upload\" />"
             "</form>"
             ""

+ 10 - 2
src/civetweb.c

@@ -5877,9 +5877,17 @@ int mg_upload2(struct mg_connection *conn, const char *destination_dir, int time
             break;
         }
 
-        /* Get headers for this part of the multipart message */
+        /* terminate header */
         buf[headers_len-1]=0;
-        s = &buf[bl];
+
+        /* Scan for the boundary string and skip it */
+        if (buf[0]=='-' && buf[1]=='-' && !memcmp(buf+2, boundary, boundary_len)) {
+            s = &buf[bl];
+        } else {
+            s = &buf[2];
+        }
+
+        /* Get headers for this part of the multipart message */
         memset(&part_request_info, 0, sizeof(part_request_info));
         parse_http_headers(&s, &part_request_info);
         assert(&buf[headers_len-1] == s);