Selaa lähdekoodia

Alternative to mg_upload (Step 39/?)

bel 9 vuotta sitten
vanhempi
commit
5facf29f71
2 muutettua tiedostoa jossa 13 lisäystä ja 2 poistoa
  1. 12 1
      examples/embedded_c/embedded_c.c
  2. 1 1
      src/handle_form.inl

+ 12 - 1
examples/embedded_c/embedded_c.c

@@ -226,12 +226,23 @@ field_get(const char *key,
 
 
 int
+field_stored(const char *path, void *user_data)
+{
+	struct mg_connection *conn = (struct mg_connection *)user_data;
+
+	mg_printf(conn, "stored as %s\r\n\r\n", path);
+
+	return 0;
+}
+
+
+int
 FormHandler(struct mg_connection *conn, void *cbdata)
 {
 	/* Handler may access the request info using mg_get_request_info */
 	const struct mg_request_info *req_info = mg_get_request_info(conn);
 	int ret;
-	struct mg_form_data_handler fdh = {field_found, field_get, 0};
+	struct mg_form_data_handler fdh = {field_found, field_get, field_stored, 0};
 
 	/* TODO: Checks before calling handle_form_data ? */
 	(void)req_info;

+ 1 - 1
src/handle_form.inl

@@ -588,7 +588,7 @@ mg_handle_form_data(struct mg_connection *conn,
 
 			if (disposition == FORM_DISPOSITION_STORE) {
 				/* Store the content to a file */
-				FILE *fstore = fopen(path, "wb");
+				fstore = fopen(path, "wb");
 				if (fstore != NULL) {
 					size_t towrite, n;